Re: Unexpected syntax error when using JSON -> in 9.3.5
| От | Tom Lane |
|---|---|
| Тема | Re: Unexpected syntax error when using JSON -> in 9.3.5 |
| Дата | |
| Msg-id | 14440.1411490484@sss.pgh.pa.us обсуждение |
| Ответ на | Unexpected syntax error when using JSON -> in 9.3.5 (Seamus Abshere <seamus@abshere.net>) |
| Список | pgsql-general |
Seamus Abshere <seamus@abshere.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
В списке pgsql-general по дате отправления: