'postgresql :: Operators invalid input syntax for type json
I have some problems of postgresql .
select '123456' :: json
and
select 123456 ::json , all of the result is 123456 ;
but select 'abc' :: json result is invalid input syntax for type json .
Is there some statement in official documents?
Solution 1:[1]
A JSON string must always be enclosed in double quotes:
SELECT '"abc"'::json;
I cannot find that explicitly mentioned in the PostgreSQL documentation, but it is clear that only a valid JSON can be cast to json.
The JSON specification documents this:
The representation of strings is similar to conventions used in the C family of programming languages. A string begins and ends with quotation marks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Laurenz Albe |
