On Thu, May 27, 2010 at 2:39 PM, Joseph Adams <joeyadams3.14...@gmail.com> wrote: > 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 <robertmh...@gmail.com> wrote: >> On Thu, May 13, 2010 at 9:47 PM, Joseph Adams >> <joeyadams3.14...@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?
Well, you should rename either the function or the type, I guess. Not sure which. Calling it json_typeof would be reasonable... > 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. Yeah, I don't think you want to go that way. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers