diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-05-29 19:29:42 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-05-29 19:29:42 -0400 |
commit | 68cff231e3a3d0ca9988cf1fde5a3be53235b3bb (patch) | |
tree | 75e35bf8b3e66fc9290dd370e3e6190970c8a873 /src/backend/utils/adt/jsonfuncs.c | |
parent | e45c5be99d08d7bb6708d7bb1dd0f5d99798c6aa (diff) | |
download | postgresql-68cff231e3a3d0ca9988cf1fde5a3be53235b3bb.tar.gz postgresql-68cff231e3a3d0ca9988cf1fde5a3be53235b3bb.zip |
Make edge-case behavior of jsonb_populate_record match json_populate_record
json_populate_record throws an error if asked to convert a JSON scalar
or array into a composite type. jsonb_populate_record was returning
a record full of NULL fields instead. It seems better to make it
throw an error for this case as well.
Nikita Glukhov
Discussion: https://postgr.es/m/fbd1d566-bba0-a3de-d6d0-d3b1d7c24ff2@postgrespro.ru
Diffstat (limited to 'src/backend/utils/adt/jsonfuncs.c')
-rw-r--r-- | src/backend/utils/adt/jsonfuncs.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index bfd6cd9cbc5..d7ece68c18d 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -2682,9 +2682,24 @@ JsValueToJsObject(JsValue *jsv, JsObject *jso) if (jbv->type == jbvBinary && JsonContainerIsObject(jbv->val.binary.data)) + { jso->val.jsonb_cont = jbv->val.binary.data; + } else - jso->val.jsonb_cont = NULL; + { + bool is_scalar; + + is_scalar = IsAJsonbScalar(jbv) || + (jbv->type == jbvBinary && + JsonContainerIsScalar(jbv->val.binary.data)); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + is_scalar + ? errmsg("cannot call %s on a scalar", + "populate_composite") + : errmsg("cannot call %s on an array", + "populate_composite"))); + } } } |