select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / AGGREGATE FUNCTIONS

Behaves in the same way as json_array but as an aggregate function so it only takes one value_expression parameter.

Signatures & examples

json_arrayagg ( [ value_expression ] [ ORDER BY sort_expression ] [ { NULL | ABSENT } ON NULL ] [ RETURNING data_type [ FORMAT JSON [ ENCODING UTF8 ] ] ])
Behaves in the same way as json_array but as an aggregate function so it only takes one value_expression parameter. If ABSENT ON NULL is specified, any NULL values are omitted. If ORDER BY is specified, the elements will appear in the array in that order rather than in the input order.
SELECT json_arrayagg(v) FROM (VALUES(2),(1)) t(v) → [2, 1]
Version history 1
  1. PG 15 → 16added

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source