how to set type for jsonb[] for play-scala anorm pgsql
Many frameworks don't support SQL arrays. There's an SQL standard for arrays but most clients have partial support or no support at all for it.
In PostgreSQL type[]
is an array of type
. So jsonb[]
is an array of jsonb
. Your client does not appear to understand this - either it doesn't support arrays, or it has special-cased array support on a per-data-type basis.
Luckily, you don't need a SQL array of jsonb
, because jsonb
stores JSON the JavaScript Serialized Object Notation. JSON defines both objects and arrays. So you can have an array of objects inside the jsonb
field. No need for SQL arrays.
This is an SQL array of jsonb
values, where each jsonb
value is a single object (dictionary):
test=> SELECT ARRAY[ '{ "x": 1, "y": 2 }', '{ "a": 3, "b": 4 }' ] :: jsonb[]; array ----------------------------------------------------- {"{ \"x\": 1, \"y\": 2 }","{ \"a\": 3, \"b\": 4 }"}(1 row)
It has the data type jsonb[]
. Note the use of the PostgreSQL ARRAY[...]
constructor notation, and note that the 'string literals'
containing the json
objects are inside the array.
This is a single jsonb
field, containing an array of objects:
test=> SELECT ' [ { "x": 1, "y": 2 }, { "a": 3, "b": 4 } ]' :: jsonb; jsonb -------------------------------------- [{"x": 1, "y": 2}, {"a": 3, "b": 4}](1 row)
Note that it's a single string literal containing a json-serialization of an array of objects.