JSON_ARRAYAGG
MariaDB starting with 10.5.0
JSON_ARRAYAGG was added in MariaDB 10.5.0.
Syntax
JSON_ARRAYAGG(column_or_expression)
Description
JSON_ARRAYAGG
returns a JSON array containing an element for each value in a given set of JSON or SQL values. It acts on a column or an expression that evaluates to a single value.
Returns NULL in the case of an error, or if the result contains no rows.
JSON_ARRAYAGG
cannot currently be used as a window function.
The full syntax is as follows:
JSON_ARRAYAGG([DISTINCT] expr [,expr ...] [ORDER BY {unsigned_integer | col_name | expr} [ASC | DESC] [,col_name ...]] [LIMIT {[offset,] row_count | row_count OFFSET offset}])
Examples
CREATE TABLE t1 (a INT, b INT); INSERT INTO t1 VALUES (1, 1),(2, 1), (1, 1),(2, 1), (3, 2),(2, 2),(2, 2),(2, 2); SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1; +-------------------+-------------------+ | JSON_ARRAYAGG(a) | JSON_ARRAYAGG(b) | +-------------------+-------------------+ | [1,2,1,2,3,2,2,2] | [1,1,1,1,2,2,2,2] | +-------------------+-------------------+ SELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1 GROUP BY b; +------------------+------------------+ | JSON_ARRAYAGG(a) | JSON_ARRAYAGG(b) | +------------------+------------------+ | [1,2,1,2] | [1,1,1,1] | | [3,2,2,2] | [2,2,2,2] | +------------------+------------------+
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.
© 2021 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/json_arrayagg/