Search Postgresql Archives

Re: Unexpected syntax error when using JSON -> in 9.3.5

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Seamus Abshere <seamus@xxxxxxxxxxx> writes:
>> foobar=# select coalesce('{}'::json->'a', 1);
>> ERROR:  COALESCE types json and integer cannot be matched

Right ...

> but check it out when I use a string instead of an integer:

>> foobar=# select coalesce('{}'::json->'a', 'b');
>> ERROR:  invalid input syntax for type json

This is expected.  The parser correctly determines that the json->text
operator returns json, and it knows that the two arguments of coalesce
must resolve as the same type, so it tries to coerce the untyped literal
to json --- which means passing that string to the json input function.
A quoted literal is not automatically a string in Postgres, it can get
resolved as some other type if required by context.  In the first example
the integer literal has a well-defined type, but bare quoted literals are
not considered to have a known type.

			regards, tom lane


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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux