I have data objects that are in the format
{
"1": [
{
"2": 17
}
],
"3": 126
}
and stored in PostgreSql database in a column with the type json
.
How can I query these, I’ve tried:
json_each(sc.data::json)
returns ERROR: cannot deconstruct a scalar
If I try
sc.data::json->'1'
it returns null
.
Ideally, I would like to get some fields from the "1" array.
2
Answers
Thanks to the effort from @SelVazi and @Bergi, I have realized that my data was wrong. It was a common escaped string instead of a JSON object.
The query to fix it is
After doing this all of the queries start working as expected, f.x.
The error means that in your data column there maybe one or more
Simple scalar/primitive value
they can be numbers, quoted strings, true, false, or null.I have reproduced your error :
Result OK :
But when add one scalar value not null I got error
Demo here