Re: JSON manipulation functions - Mailing list pgsql-hackers

From Tom Lane
Subject Re: JSON manipulation functions
Date
Msg-id 6547.1274988907@sss.pgh.pa.us
Whole thread Raw
In response to Re: JSON manipulation functions  (Joseph Adams <joeyadams3.14159@gmail.com>)
Responses Re: JSON manipulation functions
List pgsql-hackers
Joseph Adams <joeyadams3.14159@gmail.com> writes:
> 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, that might not be the behavior you expected, but that doesn't
make it wrong.  The above is, by convention, equivalent to
'[1,2,3]'::json_type, so it's acting as per convention.

If the function is a cast function (which it is), it *should* be named
after the destination type.  Doing anything else will violate numerous
longstanding expectations.  You might want to read the comments about
function-calls-as-casts in func_get_detail().
        regards, tom lane


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: [9.1] pg_stat_get_backend_server_addr
Next
From: Robert Haas
Date:
Subject: Re: JSON manipulation functions