JSON_ARRAYAGG¶
JSON_ARRAYAGG constructs a JSON array as an aggregation of values from table rows.
- value
-
Specifies a constant, table column, or expression to be aggregated.
- ORDER BY
-
Causes the items in the aggregate to be ordered in the output array. If value is a JSON_OBJECT or JSON_ARRAY constructor, the ORDER BY columns can include columns used by the JSON_OBJECT or JSON_ARRAY queries.
- NULL ON NULL | ABSENT ON NULL
-
Specifies how nulls are handled. NULL ON NULL inserts nulls as SQL nulls. ABSENT ON NULL omits null values. Default is ABSENT ON NULL.
- RETURNING datatype
-
Specifies the data type of the result. Datatype can be any string data type. Default is varchar(4000).
Examples
The query:
returns: ["1A","2A","2A","2B"]
returns two rows:
The query:
returns two rows: