From 298191036cce3b7634fd4d4b71eeb29def103f0b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 14 Oct 2026 14:00:30 -0400 Subject: [PATCH] Doc: improve documentation of the JSON object aggregates. Say which value wins for a repeated key, and how skipped null values interact with that and with the unique check. Also point out that duplicate keys behave differently for json and jsonb cases. (I still think that's a bug, but at least now it's documented.) Author: shihao zhong Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CAGRkXqTCfSu=aEUCvKDTGroEWOcyz3MCv4Xi8x1PZ1T1rEmG=Q@mail.gmail.com Backpatch-through: 14 --- doc/src/sgml/func.sgml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 68219107512..78d9469bc92 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -21986,6 +21986,9 @@ SELECT NULLIF(value, '(none)') ... are coerced to text; value arguments are converted as per to_json or to_jsonb. Values can be null, but keys cannot. + If a key appears more than once, the json result keeps + every pair, while the jsonb result keeps only the last + value for that key. No @@ -22013,8 +22016,11 @@ SELECT NULLIF(value, '(none)') ... Collects all the key/value pairs into a JSON object. Key arguments are coerced to text; value arguments are converted as per to_json or to_jsonb. - The key can not be null. If the - value is null then the entry is skipped, + The key cannot be null. If the + value is null then the pair is skipped. + Duplicate keys are handled as for json_object_agg + and jsonb_object_agg, after removing any pairs + with null values. No @@ -22071,9 +22077,10 @@ SELECT NULLIF(value, '(none)') ... Collects all the key/value pairs into a JSON object. Key arguments are coerced to text; value arguments are converted as per to_json or to_jsonb. - The key can not be null. If the - value is null then the entry is skipped. - If there is a duplicate key an error is thrown. + The key cannot be null. If the + value is null then the pair is skipped. + If there is a duplicate key (including pairs with null values) + an error is thrown. No