mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Correct handling of NULL arguments in json funcs.
Per gripe from Tom Lane.
This commit is contained in:
@ -1217,8 +1217,8 @@ Datum
|
|||||||
json_populate_record(PG_FUNCTION_ARGS)
|
json_populate_record(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
|
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
|
||||||
text *json = PG_GETARG_TEXT_P(1);
|
text *json;
|
||||||
bool use_json_as_text = PG_GETARG_BOOL(2);
|
bool use_json_as_text;
|
||||||
HTAB *json_hash;
|
HTAB *json_hash;
|
||||||
HeapTupleHeader rec;
|
HeapTupleHeader rec;
|
||||||
Oid tupType;
|
Oid tupType;
|
||||||
@ -1234,6 +1234,7 @@ json_populate_record(PG_FUNCTION_ARGS)
|
|||||||
char fname[NAMEDATALEN];
|
char fname[NAMEDATALEN];
|
||||||
JsonHashEntry hashentry;
|
JsonHashEntry hashentry;
|
||||||
|
|
||||||
|
use_json_as_text = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2);
|
||||||
|
|
||||||
if (!type_is_rowtype(argtype))
|
if (!type_is_rowtype(argtype))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -1267,6 +1268,8 @@ json_populate_record(PG_FUNCTION_ARGS)
|
|||||||
tupTypmod = HeapTupleHeaderGetTypMod(rec);
|
tupTypmod = HeapTupleHeaderGetTypMod(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json = PG_GETARG_TEXT_P(1);
|
||||||
|
|
||||||
json_hash = get_json_object_as_hash(json, "json_populate_record", use_json_as_text);
|
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)
|
json_populate_recordset(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
|
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
|
||||||
text *json = PG_GETARG_TEXT_P(1);
|
text *json;
|
||||||
bool use_json_as_text = PG_GETARG_BOOL(2);
|
bool use_json_as_text;
|
||||||
ReturnSetInfo *rsi;
|
ReturnSetInfo *rsi;
|
||||||
MemoryContext old_cxt;
|
MemoryContext old_cxt;
|
||||||
Oid tupType;
|
Oid tupType;
|
||||||
@ -1573,6 +1576,8 @@ json_populate_recordset(PG_FUNCTION_ARGS)
|
|||||||
JsonSemAction sem;
|
JsonSemAction sem;
|
||||||
PopulateRecordsetState state;
|
PopulateRecordsetState state;
|
||||||
|
|
||||||
|
use_json_as_text = PG_ARGISNULL(2) ? false : PG_GETARG_BOOL(2);
|
||||||
|
|
||||||
if (!type_is_rowtype(argtype))
|
if (!type_is_rowtype(argtype))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||||
@ -1616,6 +1621,8 @@ json_populate_recordset(PG_FUNCTION_ARGS)
|
|||||||
if (PG_ARGISNULL(1))
|
if (PG_ARGISNULL(1))
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
|
|
||||||
|
json = PG_GETARG_TEXT_P(1);
|
||||||
|
|
||||||
if (PG_ARGISNULL(0))
|
if (PG_ARGISNULL(0))
|
||||||
rec = NULL;
|
rec = NULL;
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user