Skip to content

json_object_agg_unique_strict ​

Collect rows into a native JSON object.

Syntax

text
json_object_agg_unique_strict(key,value)

Arguments

Scalar non-NULL keys and native values. Skip SQL NULL values; retain a JSON null value. All keys, including skipped NULL-value keys, must be unique; duplicates raise DUPLICATE_JSON_KEY. Plain JSON preserves object input order and nested duplicates. Tuple values use named/fN fields. FILTER, DISTINCT, aggregate ordering, and ordinary windows apply.

Returned value

Native JSON. No input rows returns SQL NULL; rows containing only skipped SQL NULL values produce an empty container.

Examples

sql
CREATE TABLE attributes (name TEXT, value INTEGER);
INSERT INTO attributes VALUES ('a',1),('b',NULL);
sql
SELECT json_object_agg_unique_strict(name,value) FROM attributes FORMAT csv;
text
"{""a"":1}"