Re: JSON manipulation functions
От | Joseph Adams |
---|---|
Тема | Re: JSON manipulation functions |
Дата | |
Msg-id | AANLkTik4vcQEkhJvLHzITKmMe--K8TWGU9ixW0agIGtJ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: JSON manipulation functions (Robert Haas <robertmhaas@gmail.com>) |
Ответы |
Re: JSON manipulation functions
Re: JSON manipulation functions |
Список | pgsql-hackers |
I've started implementing the JSON datatype; the repo is at http://git.postgresql.org/gitweb?p=json-datatype.git . On Fri, May 14, 2010 at 1:15 PM, Robert Haas <robertmhaas@gmail.com> wrote: > On Thu, May 13, 2010 at 9:47 PM, Joseph Adams > <joeyadams3.14159@gmail.com> wrote: >> Would it be a bad idea to give an enum and a function the same name >> (which appears to be allowed by PostgreSQL) ? If so, json_type(json) >> could be json_typeof(json) or something instead. > > No, I think that's a fine idea. I tried making a function named json_type that has the same name as the type json_type. However, this doesn't work as expected: SELECT json_type('[1,2,3]'); Instead of calling json_type with '[1,2,3]' casted to JSON, it's trying to cast '[1,2,3]' to json_type. Is there a way to override this behavior, or would I be better off renaming the function? Note that if the function were renamed, the literal would implicitly be json: SELECT json_typeof('[1,2,3]'); -- works I tried this: CREATE OR REPLACE FUNCTION json_type(json) RETURNS json_type AS 'MODULE_PATHNAME','json_get_type' LANGUAGE C STRICT IMMUTABLE; CREATE CAST (json AS json_type) WITH FUNCTION json_type(json); However, json_type('[1,2,3]') still doesn't work (it doesn't infer that '[1,2,3]' should be casted to json first). I also tried each of AS ASSIGNMENT and AS IMPLICIT as well.
В списке pgsql-hackers по дате отправления: