select open change scope Open full search

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

FUNCTIONS / JSON FUNCTIONS AND OPERATORS

Constructs a JSON array from either a series of value_expression parameters or from the results of query_expression, which must be a SELECT query returning a single column.

Signatures & examples

json_array ( [ { value_expression [ FORMAT JSON ] } [, ...] ] [ { NULL | ABSENT } ON NULL ] [ RETURNING data_type [ FORMAT JSON [ ENCODING UTF8 ] ] ])
Constructs a JSON array from either a series of value_expression parameters or from the results of query_expression, which must be a SELECT query returning a single column. If ABSENT ON NULL is specified, NULL values are ignored. This is always the case if a query_expression is used.
json_array(1,true,json '{"a":null}') → [1, true, {"a":null}]
json_array(SELECT * FROM (VALUES(1),(2)) t) → [1, 2]
json_array ( [ query_expression ] [ RETURNING data_type [ FORMAT JSON [ ENCODING UTF8 ] ] ])
Constructs a JSON array from either a series of value_expression parameters or from the results of query_expression, which must be a SELECT query returning a single column. If ABSENT ON NULL is specified, NULL values are ignored. This is always the case if a query_expression is used.
json_array(1,true,json '{"a":null}') → [1, true, {"a":null}]
json_array(SELECT * FROM (VALUES(1),(2)) t) → [1, 2]
Version history 2
  1. PG 18 → 19changed
  2. PG 15 → 16added

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