aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonb_util.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2015-05-26 11:16:52 -0400
committerAndrew Dunstan <andrew@dunslane.net>2015-05-26 11:23:39 -0400
commit10eb60c2dc9461b56cf90cf05032a078eef7243d (patch)
tree2e88a344ea5439330fca416761c717adc2aa25f7 /src/backend/utils/adt/jsonb_util.c
parent833c3961d9f22b46c32eeb9c4e73d334864994ed (diff)
downloadpostgresql-10eb60c2dc9461b56cf90cf05032a078eef7243d.tar.gz
postgresql-10eb60c2dc9461b56cf90cf05032a078eef7243d.zip
Add all structured objects passed to pushJsonbValue piecewise.
Commit 9b74f32cdbff8b9be47fc69164eae552050509ff did this for objects of type jbvBinary, but in trying further to simplify some of the new jsonb code I discovered that objects of type jbvObject or jbvArray passed as WJB_ELEM or WJB_VALUE also caused problems. These too are now added component by component. Backpatch to 9.4.
Diffstat (limited to 'src/backend/utils/adt/jsonb_util.c')
-rw-r--r--src/backend/utils/adt/jsonb_util.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.c
index e94c4ccb0bb..6e608cb1523 100644
--- a/src/backend/utils/adt/jsonb_util.c
+++ b/src/backend/utils/adt/jsonb_util.c
@@ -509,8 +509,8 @@ fillJsonbValue(JsonbContainer *container, int index,
* "raw scalar" pseudo array to append it - the actual scalar should be passed
* next and it will be added as the only member of the array.
*
- * Values of type jvbBinary, which are rolled up arrays and objects,
- * are unpacked before being added to the result.
+ * All non-scalar types (jvbBinary, jbvArray and jbvObject) passed as
+ * elements or values are unpacked before being added to the result.
*/
JsonbValue *
pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
@@ -522,14 +522,18 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
JsonbIteratorToken tok;
if (!jbval || (seq != WJB_ELEM && seq != WJB_VALUE) ||
- jbval->type != jbvBinary)
+ IsAJsonbScalar(jbval))
{
/* drop through */
return pushJsonbValueScalar(pstate, seq, jbval);
}
- /* unpack the binary and add each piece to the pstate */
- it = JsonbIteratorInit(jbval->val.binary.data);
+ /* unpack the data and add each piece to the pstate */
+ if (jbval->type == jbvBinary)
+ it = JsonbIteratorInit(jbval->val.binary.data);
+ else
+ it = JsonbIteratorInit(jbval);
+
while ((tok = JsonbIteratorNext(&it, &v, false)) != WJB_DONE)
res = pushJsonbValueScalar(pstate, tok,
tok < WJB_BEGIN_ARRAY ? &v : NULL);