I have an array column but when I output it using SQL SELECT, it looks like
{{"a":"b","c":"d"},{"e":"f","g":"h"}}
But why does it start and end with {{
and }}
? Shouldn't it be [{
and }]
for arrays? Inside output of JSONB
columns, arrays look as expected (square brackets, not curly braces, surrounding the array values).
Have I done something wrong, or is the output above truly an array of objects?
Best Answer
From the docs in Array Input and Output Syntax
Not sure if stingification of
ARRAY
is in the spec or not, but for PostgreSQL it's perfectly normal to stingify it with{}
. Note, this is not symmetrical with the literal syntax to create an array.But you can see that it's valid and to be expected because you can cast to an array explicitly.
If in your case you have two
jsonb
in theARRAY
, it'll get stringified as suchNote that a two JSON-objects in a PostgreSQL array, is different from two objects in a JSON array.