From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Seamus Abshere <seamus(at)abshere(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Unexpected syntax error when using JSON -> in 9.3.5 |
Date: | 2014-09-23 16:41:24 |
Message-ID: | 14440.1411490484@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Seamus Abshere <seamus(at)abshere(dot)net> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2014-09-23 16:54:38 | Re: Will there be a JSON operator like ->> but returning numeric? |
Previous Message | David G Johnston | 2014-09-23 16:32:54 | Re: Unexpected syntax error when using JSON -> in 9.3.5 |