aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonb.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2015-07-24 09:40:46 -0400
committerAndrew Dunstan <andrew@dunslane.net>2015-07-24 09:40:46 -0400
commitd9a356ff2e6bb7ed5fb1145af49fa3e51e68a98a (patch)
tree2320f3f55faa3d0e3c92f2b4a39d9f22dcaeda46 /src/backend/utils/adt/jsonb.c
parentc1ca3a19df376bcbb6d651d15b9a4ffcaa377ff1 (diff)
downloadpostgresql-d9a356ff2e6bb7ed5fb1145af49fa3e51e68a98a.tar.gz
postgresql-d9a356ff2e6bb7ed5fb1145af49fa3e51e68a98a.zip
Fix treatment of nulls in jsonb_agg and jsonb_object_agg
The wrong is_null flag was being passed to datum_to_json. Also, null object key values are not permitted, and this was not being checked for. Add regression tests covering these cases, and also add those tests to the json set, even though it was doing the right thing. Fixes bug #13514, initially diagnosed by Tom Lane.
Diffstat (limited to 'src/backend/utils/adt/jsonb.c')
-rw-r--r--src/backend/utils/adt/jsonb.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index e68972221ab..154bc3626c9 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -705,6 +705,7 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
if (is_null)
{
+ Assert(!key_scalar);
jb.type = jbvNull;
}
else if (key_scalar &&
@@ -1606,7 +1607,7 @@ jsonb_agg_transfn(PG_FUNCTION_ARGS)
memset(&elem, 0, sizeof(JsonbInState));
- datum_to_jsonb(val, false, &elem, tcategory, outfuncoid, false);
+ datum_to_jsonb(val, PG_ARGISNULL(1), &elem, tcategory, outfuncoid, false);
jbelem = JsonbValueToJsonb(elem.res);
@@ -1752,7 +1753,12 @@ jsonb_object_agg_transfn(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not determine input data type")));
- val = PG_ARGISNULL(1) ? (Datum) 0 : PG_GETARG_DATUM(1);
+ if (PG_ARGISNULL(1))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("field name must not be null")));
+
+ val = PG_GETARG_DATUM(1);
jsonb_categorize_type(val_type,
&tcategory, &outfuncoid);
@@ -1777,7 +1783,7 @@ jsonb_object_agg_transfn(PG_FUNCTION_ARGS)
memset(&elem, 0, sizeof(JsonbInState));
- datum_to_jsonb(val, false, &elem, tcategory, outfuncoid, false);
+ datum_to_jsonb(val, PG_ARGISNULL(2), &elem, tcategory, outfuncoid, false);
jbval = JsonbValueToJsonb(elem.res);