@@ -101,7 +101,8 @@ static void appendElement(JsonbParseState *pstate, const JsonbValue *scalarVal);
101
101
static int lengthCompareJsonbPair (const void * a ,const void * b ,void * arg );
102
102
static void uniqueifyJsonbObject (JsonbValue * object );
103
103
static JsonbValue * pushSingleScalarJsonbValue (JsonbParseState * * pstate ,
104
- const JsonbValue * jbval );
104
+ const JsonbValue * jbval ,
105
+ bool unpackBinary );
105
106
static void jsonbInitContainer (JsonContainerData * jc ,JsonbContainer * jbc ,int len );
106
107
107
108
JsonValue *
@@ -162,7 +163,7 @@ JsonValueFlatten(const JsonValue *val, JsonValueEncoder encoder,
162
163
if (IsAJsonbScalar (val ))
163
164
{
164
165
JsonbParseState * pstate = NULL ;
165
- val = pushSingleScalarJsonbValue (& pstate ,val );
166
+ val = pushSingleScalarJsonbValue (& pstate ,val , true );
166
167
}
167
168
else
168
169
{
@@ -694,8 +695,8 @@ JsonbParseStateClone(JsonbParseState *state)
694
695
* are unpacked before being added to the result.
695
696
*/
696
697
JsonbValue *
697
- pushJsonbValue (JsonbParseState * * pstate ,JsonbIteratorToken seq ,
698
- const JsonbValue * jbval )
698
+ pushJsonbValueExt (JsonbParseState * * pstate ,JsonbIteratorToken seq ,
699
+ const JsonbValue * jbval , bool unpackBinary )
699
700
{
700
701
JsonIterator * it ;
701
702
JsonbValue * res = NULL ;
@@ -709,25 +710,29 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
709
710
for (i = 0 ;i < jbval -> val .object .nPairs ;i ++ )
710
711
{
711
712
pushJsonbValue (pstate ,WJB_KEY ,& jbval -> val .object .pairs [i ].key );
712
- pushJsonbValue (pstate ,WJB_VALUE ,& jbval -> val .object .pairs [i ].value );
713
+ pushJsonbValueExt (pstate ,WJB_VALUE ,& jbval -> val .object .pairs [i ].value , unpackBinary );
713
714
}
714
715
715
716
return pushJsonbValue (pstate ,WJB_END_OBJECT ,NULL );
716
717
}
717
718
718
719
if (jbval && (seq == WJB_ELEM || seq == WJB_VALUE )&& jbval -> type == jbvArray )
719
720
{
721
+ if (jbval -> val .array .rawScalar )
722
+ return pushJsonbValue (pstate ,seq ,& jbval -> val .array .elems [0 ]);
723
+
720
724
pushJsonbValue (pstate ,WJB_BEGIN_ARRAY ,NULL );
725
+
721
726
for (i = 0 ;i < jbval -> val .array .nElems ;i ++ )
722
727
{
723
- pushJsonbValue (pstate ,WJB_ELEM ,& jbval -> val .array .elems [i ]);
728
+ pushJsonbValueExt (pstate ,WJB_ELEM ,& jbval -> val .array .elems [i ], unpackBinary );
724
729
}
725
730
726
731
return pushJsonbValue (pstate ,WJB_END_ARRAY ,NULL );
727
732
}
728
733
729
734
if (!jbval || (seq != WJB_ELEM && seq != WJB_VALUE )||
730
- jbval -> type != jbvBinary )
735
+ jbval -> type != jbvBinary || ! unpackBinary )
731
736
{
732
737
/* drop through */
733
738
return pushJsonbValueScalar (pstate ,seq ,jbval );
@@ -815,7 +820,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
815
820
appendValue (* pstate ,scalarVal );
816
821
break ;
817
822
case WJB_ELEM :
818
- Assert (IsAJsonbScalar (scalarVal ));
823
+ /* Assert(IsAJsonbScalar(scalarVal)); */
819
824
appendElement (* pstate ,scalarVal );
820
825
break ;
821
826
case WJB_END_OBJECT :
@@ -854,7 +859,8 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
854
859
}
855
860
856
861
static JsonbValue *
857
- pushSingleScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval )
862
+ pushSingleScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
863
+ bool unpackBinary )
858
864
{
859
865
/* single root scalar */
860
866
JsonbValue va ;
@@ -864,20 +870,21 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval)
864
870
va .val .array .nElems = 1 ;
865
871
866
872
pushJsonbValue (pstate ,WJB_BEGIN_ARRAY ,& va );
867
- pushJsonbValue (pstate ,WJB_ELEM ,jbval );
873
+ pushJsonbValueExt (pstate ,WJB_ELEM ,jbval , unpackBinary );
868
874
return pushJsonbValue (pstate ,WJB_END_ARRAY ,NULL );
869
875
}
870
876
871
877
static JsonbValue *
872
878
pushNestedScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
873
- bool isKey )
879
+ bool isKey , bool unpackBinary )
874
880
{
875
881
switch ((* pstate )-> contVal .type )
876
882
{
877
883
case jbvArray :
878
- return pushJsonbValue (pstate ,WJB_ELEM ,jbval );
884
+ return pushJsonbValueExt (pstate ,WJB_ELEM ,jbval , unpackBinary );
879
885
case jbvObject :
880
- return pushJsonbValue (pstate ,isKey ?WJB_KEY :WJB_VALUE ,jbval );
886
+ return pushJsonbValueExt (pstate ,isKey ?WJB_KEY :WJB_VALUE ,jbval ,
887
+ unpackBinary );
881
888
default :
882
889
elog (ERROR ,"unexpected parent of nested structure" );
883
890
return NULL ;
@@ -886,11 +893,11 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
886
893
887
894
JsonbValue *
888
895
pushScalarJsonbValue (JsonbParseState * * pstate ,const JsonbValue * jbval ,
889
- bool isKey )
896
+ bool isKey , bool unpackBinary )
890
897
{
891
898
return * pstate == NULL
892
- ?pushSingleScalarJsonbValue (pstate ,jbval )
893
- :pushNestedScalarJsonbValue (pstate ,jbval ,isKey );
899
+ ?pushSingleScalarJsonbValue (pstate ,jbval , unpackBinary )
900
+ :pushNestedScalarJsonbValue (pstate ,jbval ,isKey , unpackBinary );
894
901
895
902
}
896
903
@@ -2198,5 +2205,5 @@ jsonbContainerOps =
2198
2205
jsonbFindValueInArray ,
2199
2206
jsonbGetArrayElement ,
2200
2207
NULL ,
2201
- JsonbToCString ,
2208
+ JsonbToCStringRaw ,
2202
2209
};