Joseph Adams <joeyadams3.14...@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

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to