Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 956cc44

Browse files
committed
Revert "Simplify addJsonbToParseState()"
This reverts commit fba12c8. This relied on a commit that is also being reverted.
1 parent 86832eb commit 956cc44

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/backend/utils/adt/jsonfuncs.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,9 +3225,8 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS)
32253225
* If the parse state container is an object, the jsonb is pushed as
32263226
* a value, not a key.
32273227
*
3228-
* If the new value is a root scalar, extract the value using an iterator, and
3229-
* just add that. Otherwise, add the value as the type appropriate for
3230-
* the container.
3228+
* This needs to be done using an iterator because pushJsonbValue doesn't
3229+
* like getting jbvBinary values, so we can't just push jb as a whole.
32313230
*/
32323231
static void
32333232
addJsonbToParseState(JsonbParseState **jbps, Jsonb *jb)
@@ -3237,26 +3236,36 @@ addJsonbToParseState(JsonbParseState **jbps, Jsonb *jb)
32373236
int type;
32383237
JsonbValue v;
32393238

3239+
it = JsonbIteratorInit(&jb->root);
3240+
32403241
Assert(o->type == jbvArray || o->type == jbvObject);
32413242

32423243
if (JB_ROOT_IS_SCALAR(jb))
32433244
{
3244-
it = JsonbIteratorInit(&jb->root);
3245-
32463245
(void) JsonbIteratorNext(&it, &v, false); /* skip array header */
32473246
(void) JsonbIteratorNext(&it, &v, false); /* fetch scalar value */
32483247

3249-
if (o->type == jbvArray)
3250-
(void) pushJsonbValue(jbps, WJB_ELEM, &v);
3251-
else
3252-
(void) pushJsonbValue(jbps, WJB_VALUE, &v);
3248+
switch (o->type)
3249+
{
3250+
case jbvArray:
3251+
(void) pushJsonbValue(jbps, WJB_ELEM, &v);
3252+
break;
3253+
case jbvObject:
3254+
(void) pushJsonbValue(jbps, WJB_VALUE, &v);
3255+
break;
3256+
default:
3257+
elog(ERROR, "unexpected parent of nested structure");
3258+
}
32533259
}
32543260
else
32553261
{
3256-
if (o->type == jbvArray)
3257-
(void) pushJsonbValue(jbps, WJB_ELEM, &jb->root);
3258-
else
3259-
(void) pushJsonbValue(jbps, WJB_VALUE, &jb->root);
3262+
while ((type = JsonbIteratorNext(&it, &v, false)) != WJB_DONE)
3263+
{
3264+
if (type == WJB_KEY || type == WJB_VALUE || type == WJB_ELEM)
3265+
(void) pushJsonbValue(jbps, type, &v);
3266+
else
3267+
(void) pushJsonbValue(jbps, type, NULL);
3268+
}
32603269
}
32613270

32623271
}

0 commit comments

Comments
 (0)