b.yordanov2@gmail.com writes:
> jsonb_object_agg() appears to fail when the second argument (in this case
> attributes->z->'tt') is a nonexistent jsonb column (there is
> attributes->z->'t' but not 'tt').
Seems to be failure to handle nulls properly. The attached patch stops
the crash for me, but I've not checked to see if the results are "right",
nor scouted around to see if there are similar bugs nearby.
regards, tom lane
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index e689722..b82bde0 100644
*** a/src/backend/utils/adt/jsonb.c
--- b/src/backend/utils/adt/jsonb.c
*************** jsonb_agg_transfn(PG_FUNCTION_ARGS)
*** 1606,1612 ****
memset(&elem, 0, sizeof(JsonbInState));
! datum_to_jsonb(val, false, &elem, tcategory, outfuncoid, false);
jbelem = JsonbValueToJsonb(elem.res);
--- 1606,1612 ----
memset(&elem, 0, sizeof(JsonbInState));
! datum_to_jsonb(val, PG_ARGISNULL(1), &elem, tcategory, outfuncoid, false);
jbelem = JsonbValueToJsonb(elem.res);
*************** jsonb_object_agg_transfn(PG_FUNCTION_ARG
*** 1759,1765 ****
memset(&elem, 0, sizeof(JsonbInState));
! datum_to_jsonb(val, false, &elem, tcategory, outfuncoid, true);
jbkey = JsonbValueToJsonb(elem.res);
--- 1759,1765 ----
memset(&elem, 0, sizeof(JsonbInState));
! datum_to_jsonb(val, PG_ARGISNULL(1), &elem, tcategory, outfuncoid, true);
jbkey = JsonbValueToJsonb(elem.res);
*************** jsonb_object_agg_transfn(PG_FUNCTION_ARG
*** 1777,1783 ****
memset(&elem, 0, sizeof(JsonbInState));
! datum_to_jsonb(val, false, &elem, tcategory, outfuncoid, false);
jbval = JsonbValueToJsonb(elem.res);
--- 1777,1783 ----
memset(&elem, 0, sizeof(JsonbInState));
! datum_to_jsonb(val, PG_ARGISNULL(2), &elem, tcategory, outfuncoid, false);
jbval = JsonbValueToJsonb(elem.res);