@@ -419,6 +419,7 @@ static JsonItem *getScalar(JsonItem *scalar, enum jbvType type);
419
419
static JsonItem * getNumber (JsonItem * scalar );
420
420
static bool convertJsonDoubleToNumeric (JsonItem * dbl , JsonItem * num );
421
421
static JsonbValue * wrapItemsInArray (const JsonValueList * items , bool isJsonb );
422
+ static JsonItem * wrapItem (JsonItem * jbv , bool isJsonb );
422
423
static text * JsonItemUnquoteText (JsonItem * jsi , bool isJsonb );
423
424
static JsonItem * wrapJsonObjectOrArray (JsonItem * js , JsonItem * buf ,
424
425
bool isJsonb );
@@ -3646,6 +3647,45 @@ convertJsonDoubleToNumeric(JsonItem *dbl, JsonItem *num)
3646
3647
return true;
3647
3648
}
3648
3649
3650
+ /*
3651
+ * Wrap a non-array SQL/JSON item into an array for applying array subscription
3652
+ * path steps in lax mode.
3653
+ */
3654
+ static JsonItem *
3655
+ wrapItem (JsonItem * jsi , bool isJsonb )
3656
+ {
3657
+ JsonbParseState * ps = NULL ;
3658
+ JsonItem jsibuf ;
3659
+ JsonbValue jbvbuf ;
3660
+
3661
+ switch (JsonbType (jsi ))
3662
+ {
3663
+ case jbvArray :
3664
+ /* Simply return an array item. */
3665
+ return jsi ;
3666
+
3667
+ case jbvObject :
3668
+ /*
3669
+ * Need to wrap object into a binary JsonbValue for its unpacking
3670
+ * in pushJsonbValue().
3671
+ */
3672
+ if (!JsonItemIsBinary (jsi ))
3673
+ jsi = JsonxWrapInBinary (jsi , & jsibuf , isJsonb );
3674
+ break ;
3675
+
3676
+ default :
3677
+ /* Ordinary scalars can be pushed directly. */
3678
+ break ;
3679
+ }
3680
+
3681
+ pushJsonbValue (& ps , WJB_BEGIN_ARRAY , NULL );
3682
+ (isJsonb ? pushJsonbValue : pushJsonValue )(& ps , WJB_ELEM ,
3683
+ JsonItemToJsonbValue (jsi , & jbvbuf ));
3684
+ jsi = JsonbValueToJsonItem (pushJsonbValue (& ps , WJB_END_ARRAY , NULL ), & jsibuf );
3685
+
3686
+ return JsonxWrapInBinary (jsi , NULL , isJsonb );
3687
+ }
3688
+
3649
3689
/* Construct a JSON array from the item list */
3650
3690
static JsonbValue *
3651
3691
wrapItemsInArray (const JsonValueList * items , bool isJsonb )
0 commit comments