Skip to content

Commit 728ec97

Browse files
committed
Correct handling of NULL arguments in json funcs.
Per gripe from Tom Lane.
1 parent 410bed2 commit 728ec97

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/utils/adt/jsonfuncs.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,8 @@ Datum
12171217
json_populate_record(PG_FUNCTION_ARGS)
12181218
{
12191219
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
1220-
text *json = PG_GETARG_TEXT_P(1);
1221-
bool use_json_as_text = PG_GETARG_BOOL(2);
1220+
text *json;
1221+
bool use_json_as_text;
12221222
HTAB *json_hash;
12231223
HeapTupleHeader rec;
12241224
Oid tupType;
@@ -1234,6 +1234,7 @@ json_populate_record(PG_FUNCTION_ARGS)
12341234
char fname[NAMEDATALEN];
12351235
JsonHashEntry hashentry;
12361236

1237+
use_json_as_text = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2);
12371238

12381239
if (!type_is_rowtype(argtype))
12391240
ereport(ERROR,
@@ -1267,6 +1268,8 @@ json_populate_record(PG_FUNCTION_ARGS)
12671268
tupTypmod = HeapTupleHeaderGetTypMod(rec);
12681269
}
12691270

1271+
json = PG_GETARG_TEXT_P(1);
1272+
12701273
json_hash = get_json_object_as_hash(json, "json_populate_record", use_json_as_text);
12711274

12721275
/*
@@ -1559,8 +1562,8 @@ Datum
15591562
json_populate_recordset(PG_FUNCTION_ARGS)
15601563
{
15611564
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
1562-
text *json = PG_GETARG_TEXT_P(1);
1563-
bool use_json_as_text = PG_GETARG_BOOL(2);
1565+
text *json;
1566+
bool use_json_as_text;
15641567
ReturnSetInfo *rsi;
15651568
MemoryContext old_cxt;
15661569
Oid tupType;
@@ -1573,6 +1576,8 @@ json_populate_recordset(PG_FUNCTION_ARGS)
15731576
JsonSemAction sem;
15741577
PopulateRecordsetState state;
15751578

1579+
use_json_as_text = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2);
1580+
15761581
if (!type_is_rowtype(argtype))
15771582
ereport(ERROR,
15781583
(errcode(ERRCODE_DATATYPE_MISMATCH),
@@ -1616,6 +1621,8 @@ json_populate_recordset(PG_FUNCTION_ARGS)
16161621
if (PG_ARGISNULL(1))
16171622
PG_RETURN_NULL();
16181623

1624+
json = PG_GETARG_TEXT_P(1);
1625+
16191626
if (PG_ARGISNULL(0))
16201627
rec = NULL;
16211628
else

0 commit comments

Comments
 (0)