@@ -3225,9 +3225,8 @@ 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
- * 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.
3231
3230
*/
3232
3231
static void
3233
3232
addJsonbToParseState (JsonbParseState * * jbps , Jsonb * jb )
@@ -3237,26 +3236,36 @@ addJsonbToParseState(JsonbParseState **jbps, Jsonb *jb)
3237
3236
int type ;
3238
3237
JsonbValue v ;
3239
3238
3239
+ it = JsonbIteratorInit (& jb -> root );
3240
+
3240
3241
Assert (o -> type == jbvArray || o -> type == jbvObject );
3241
3242
3242
3243
if (JB_ROOT_IS_SCALAR (jb ))
3243
3244
{
3244
- it = JsonbIteratorInit (& jb -> root );
3245
-
3246
3245
(void ) JsonbIteratorNext (& it , & v , false); /* skip array header */
3247
3246
(void ) JsonbIteratorNext (& it , & v , false); /* fetch scalar value */
3248
3247
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
+ }
3253
3259
}
3254
3260
else
3255
3261
{
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
+ }
3260
3269
}
3261
3270
3262
3271
}
0 commit comments