@@ -452,10 +452,10 @@ static JsonbValue *setPath(JsonbIterator **it, Datum *path_elems,
452452bool * path_nulls ,int path_len ,
453453JsonbParseState * * st ,int level ,Jsonb * newval ,
454454int op_type );
455- static void setPathObject (JsonbIterator * * it ,Datum * path_elems ,
455+ static JsonbIteratorToken setPathObject (JsonbIterator * * it ,Datum * path_elems ,
456456bool * path_nulls ,int path_len ,JsonbParseState * * st ,
457457int level ,
458- Jsonb * newval ,uint32 npairs , int op_type );
458+ Jsonb * newval ,int op_type );
459459static void setPathArray (JsonbIterator * * it ,Datum * path_elems ,
460460bool * path_nulls ,int path_len ,JsonbParseState * * st ,
461461int level ,Jsonb * newval ,uint32 nelems ,int op_type );
@@ -4550,9 +4550,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
45504550break ;
45514551case WJB_BEGIN_OBJECT :
45524552(void )pushJsonbValue (st ,r ,NULL );
4553- setPathObject (it ,path_elems ,path_nulls ,path_len ,st ,level ,
4554- newval ,v .val .object .nPairs ,op_type );
4555- r = JsonbIteratorNext (it ,& v , true);
4553+ r = setPathObject (it ,path_elems ,path_nulls ,path_len ,st ,level ,
4554+ newval ,op_type );
45564555Assert (r == WJB_END_OBJECT );
45574556res = pushJsonbValue (st ,r ,NULL );
45584557break ;
@@ -4572,39 +4571,21 @@ setPath(JsonbIterator **it, Datum *path_elems,
45724571/*
45734572 * Object walker for setPath
45744573 */
4575- static void
4574+ static JsonbIteratorToken
45764575setPathObject (JsonbIterator * * it ,Datum * path_elems ,bool * path_nulls ,
45774576int path_len ,JsonbParseState * * st ,int level ,
4578- Jsonb * newval ,uint32 npairs , int op_type )
4577+ Jsonb * newval ,int op_type )
45794578{
45804579JsonbValue v ;
4581- int i ;
45824580JsonbValue k ;
4581+ JsonbIteratorToken r ;
45834582bool done = false;
45844583
45854584if (level >=path_len || path_nulls [level ])
45864585done = true;
45874586
4588- /* empty object is a special case for create */
4589- if ((npairs == 0 )&& (op_type & JB_PATH_CREATE_OR_INSERT )&&
4590- (level == path_len - 1 ))
4587+ while ((r = JsonbIteratorNext (it ,& k , true))== WJB_KEY )
45914588{
4592- JsonbValue newkey ;
4593-
4594- newkey .type = jbvString ;
4595- newkey .val .string .len = VARSIZE_ANY_EXHDR (path_elems [level ]);
4596- newkey .val .string .val = VARDATA_ANY (path_elems [level ]);
4597-
4598- (void )pushJsonbValue (st ,WJB_KEY ,& newkey );
4599- addJsonbToParseState (st ,newval );
4600- }
4601-
4602- for (i = 0 ;i < npairs ;i ++ )
4603- {
4604- JsonbIteratorToken r = JsonbIteratorNext (it ,& k , true);
4605-
4606- Assert (r == WJB_KEY );
4607-
46084589if (!done &&
46094590k .val .string .len == VARSIZE_ANY_EXHDR (path_elems [level ])&&
46104591memcmp (k .val .string .val ,VARDATA_ANY (path_elems [level ]),
@@ -4624,6 +4605,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
46244605"to replace key value." )));
46254606
46264607r = JsonbIteratorNext (it ,& v , true);/* skip value */
4608+ Assert (r == WJB_VALUE );
4609+
46274610if (!(op_type & JB_PATH_DELETE ))
46284611{
46294612(void )pushJsonbValue (st ,WJB_KEY ,& k );
@@ -4640,25 +4623,26 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
46404623}
46414624else
46424625{
4643- if ((op_type & JB_PATH_CREATE_OR_INSERT )&& !done &&
4644- level == path_len - 1 && i == npairs - 1 )
4645- {
4646- JsonbValue newkey ;
4647-
4648- newkey .type = jbvString ;
4649- newkey .val .string .len = VARSIZE_ANY_EXHDR (path_elems [level ]);
4650- newkey .val .string .val = VARDATA_ANY (path_elems [level ]);
4651-
4652- (void )pushJsonbValue (st ,WJB_KEY ,& newkey );
4653- addJsonbToParseState (st ,newval );
4654- }
4655-
46564626(void )pushJsonbValue (st ,r ,& k );
46574627r = JsonbIteratorNext (it ,& v , true);
46584628Assert (r == WJB_VALUE );
46594629(void )pushJsonbValue (st ,r ,& v );
46604630}
46614631}
4632+
4633+ if ((op_type & JB_PATH_CREATE_OR_INSERT )&& !done && level == path_len - 1 )
4634+ {
4635+ JsonbValue newkey ;
4636+
4637+ newkey .type = jbvString ;
4638+ newkey .val .string .len = VARSIZE_ANY_EXHDR (path_elems [level ]);
4639+ newkey .val .string .val = VARDATA_ANY (path_elems [level ]);
4640+
4641+ (void )pushJsonbValue (st ,WJB_KEY ,& newkey );
4642+ addJsonbToParseState (st ,newval );
4643+ }
4644+
4645+ return r ;
46624646}
46634647
46644648/*