@@ -3225,8 +3225,9 @@ jsonb_strip_nulls(PG_FUNCTION_ARGS)
3225
3225
* If the parse state container is an object, the jsonb is pushed as
3226
3226
* a value, not a key.
3227
3227
*
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.
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.
3230
3231
*/
3231
3232
static void
3232
3233
addJsonbToParseState (JsonbParseState * * jbps , Jsonb * jb )
@@ -3236,36 +3237,26 @@ addJsonbToParseState(JsonbParseState **jbps, Jsonb *jb)
3236
3237
int type ;
3237
3238
JsonbValue v ;
3238
3239
3239
- it = JsonbIteratorInit (& jb -> root );
3240
-
3241
3240
Assert (o -> type == jbvArray || o -> type == jbvObject );
3242
3241
3243
3242
if (JB_ROOT_IS_SCALAR (jb ))
3244
3243
{
3244
+ it = JsonbIteratorInit (& jb -> root );
3245
+
3245
3246
(void ) JsonbIteratorNext (& it , & v , false); /* skip array header */
3246
3247
(void ) JsonbIteratorNext (& it , & v , false); /* fetch scalar value */
3247
3248
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
- }
3249
+ if (o -> type == jbvArray )
3250
+ (void ) pushJsonbValue (jbps , WJB_ELEM , & v );
3251
+ else
3252
+ (void ) pushJsonbValue (jbps , WJB_VALUE , & v );
3259
3253
}
3260
3254
else
3261
3255
{
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
- }
3256
+ if (o -> type == jbvArray )
3257
+ (void ) pushJsonbValue (jbps , WJB_ELEM , & jb -> root );
3258
+ else
3259
+ (void ) pushJsonbValue (jbps , WJB_VALUE , & jb -> root );
3269
3260
}
3270
3261
3271
3262
}
0 commit comments