diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2013-04-15 16:20:21 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2013-04-15 16:20:21 -0400 |
commit | 728ec9731fb0b3f2de8ce66a394b71c64930f445 (patch) | |
tree | 83c24bc31fda42d05800f2c6c10d1de0001bd446 /src/backend/utils/adt/jsonfuncs.c | |
parent | 410bed2ab8c3864d7f34f9694d080adcaf446352 (diff) | |
download | postgresql-728ec9731fb0b3f2de8ce66a394b71c64930f445.tar.gz postgresql-728ec9731fb0b3f2de8ce66a394b71c64930f445.zip |
Correct handling of NULL arguments in json funcs.
Per gripe from Tom Lane.
Diffstat (limited to 'src/backend/utils/adt/jsonfuncs.c')
-rw-r--r-- | src/backend/utils/adt/jsonfuncs.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 73bcdf46b12..03378a3ea9b 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -1217,8 +1217,8 @@ Datum json_populate_record(PG_FUNCTION_ARGS) { Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0); - text *json = PG_GETARG_TEXT_P(1); - bool use_json_as_text = PG_GETARG_BOOL(2); + text *json; + bool use_json_as_text; HTAB *json_hash; HeapTupleHeader rec; Oid tupType; @@ -1234,6 +1234,7 @@ json_populate_record(PG_FUNCTION_ARGS) char fname[NAMEDATALEN]; JsonHashEntry hashentry; + use_json_as_text = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2); if (!type_is_rowtype(argtype)) ereport(ERROR, @@ -1267,6 +1268,8 @@ json_populate_record(PG_FUNCTION_ARGS) tupTypmod = HeapTupleHeaderGetTypMod(rec); } + json = PG_GETARG_TEXT_P(1); + json_hash = get_json_object_as_hash(json, "json_populate_record", use_json_as_text); /* @@ -1559,8 +1562,8 @@ Datum json_populate_recordset(PG_FUNCTION_ARGS) { Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0); - text *json = PG_GETARG_TEXT_P(1); - bool use_json_as_text = PG_GETARG_BOOL(2); + text *json; + bool use_json_as_text; ReturnSetInfo *rsi; MemoryContext old_cxt; Oid tupType; @@ -1573,6 +1576,8 @@ json_populate_recordset(PG_FUNCTION_ARGS) JsonSemAction sem; PopulateRecordsetState state; + use_json_as_text = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2); + if (!type_is_rowtype(argtype)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), @@ -1616,6 +1621,8 @@ json_populate_recordset(PG_FUNCTION_ARGS) if (PG_ARGISNULL(1)) PG_RETURN_NULL(); + json = PG_GETARG_TEXT_P(1); + if (PG_ARGISNULL(0)) rec = NULL; else |