@@ -3225,8 +3225,9 @@ 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- * 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.
32303231 */
32313232static void
32323233addJsonbToParseState (JsonbParseState * * jbps ,Jsonb * jb )
@@ -3236,36 +3237,26 @@ addJsonbToParseState(JsonbParseState **jbps, Jsonb *jb)
32363237int type ;
32373238JsonbValue v ;
32383239
3239- it = JsonbIteratorInit (& jb -> root );
3240-
32413240Assert (o -> type == jbvArray || o -> type == jbvObject );
32423241
32433242if (JB_ROOT_IS_SCALAR (jb ))
32443243{
3244+ it = JsonbIteratorInit (& jb -> root );
3245+
32453246(void )JsonbIteratorNext (& it ,& v , false);/* skip array header */
32463247(void )JsonbIteratorNext (& it ,& v , false);/* fetch scalar value */
32473248
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 );
32593253}
32603254else
32613255{
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 );
32693260}
32703261
32713262}