jsonb_object_agg_unique
Collect rows into a native JSON object.
Syntax
text
jsonb_object_agg_unique(key,value)Arguments
Scalar non-NULL keys and native values. Retain SQL NULL values as JSON null. All keys, including skipped NULL-value keys, must be unique; duplicates raise DUPLICATE_JSON_KEY. JSONB forms recursively normalize keys and final values. 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 jsonb_object_agg_unique(name,value) FROM attributes FORMAT csv;text
"{""a"":1,""b"":null}"