From 8a5f8eb456f61fa8dcf444cac64d0b241b86430e 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/func-aggregate.sgml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/func/func-aggregate.sgml b/doc/src/sgml/func/func-aggregate.sgml index 6a6a4d7e32e..c3669898f0a 100644 --- a/doc/src/sgml/func/func-aggregate.sgml +++ b/doc/src/sgml/func/func-aggregate.sgml @@ -404,6 +404,9 @@ 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 @@ -432,7 +435,10 @@ are coerced to text; value arguments are converted as per to_json or to_jsonb. The key cannot be null. If the - value is null then the entry is skipped, + 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 @@ -490,8 +496,9 @@ are coerced to text; value arguments are converted as per to_json or to_jsonb. The key cannot be null. If the - value is null then the entry is skipped. - If there is a duplicate key an error is thrown. + value is null then the pair is skipped. + If there is a duplicate key (including pairs with null values) + an error is thrown. No