@@ -716,7 +716,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
716
716
char * outputstr ;
717
717
bool numeric_error ;
718
718
JsonbValue jb ;
719
- bool scalar_jsonb = false;
720
719
721
720
check_stack_depth ();
722
721
@@ -746,10 +745,10 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
746
745
{
747
746
case JSONBTYPE_ARRAY :
748
747
array_to_jsonb_internal (val , result );
749
- break ;
748
+ return ;
750
749
case JSONBTYPE_COMPOSITE :
751
750
composite_to_jsonb (val , result );
752
- break ;
751
+ return ;
753
752
case JSONBTYPE_BOOL :
754
753
if (key_scalar )
755
754
{
@@ -843,7 +842,7 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
843
842
844
843
pg_parse_json_or_ereport (lex , & sem );
845
844
}
846
- break ;
845
+ return ;
847
846
case JSONBTYPE_JSONB :
848
847
{
849
848
Jsonb * jsonb = DatumGetJsonbP (val );
@@ -856,35 +855,33 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
856
855
(void ) JsonbIteratorNext (& it , & jb , true);
857
856
Assert (jb .type == jbvArray );
858
857
(void ) JsonbIteratorNext (& it , & jb , true);
859
- scalar_jsonb = true ;
858
+ break ;
860
859
}
861
- else
862
- {
863
- JsonbIteratorToken type ;
864
-
865
860
866
- if (result -> parseState )
867
- {
861
+ if (result -> parseState )
862
+ result -> res =
868
863
pushScalarJsonbValue (& result -> parseState ,
869
864
JsonToJsonValue (jsonb , & jb ),
870
865
false, false);
871
- return ;
872
- }
866
+ else
867
+ {
868
+ JsonbIteratorToken type ;
873
869
874
870
while ((type = JsonbIteratorNext (& it , & jb , false))
875
871
!= WJB_DONE )
876
872
{
877
- if (type == WJB_END_ARRAY || type == WJB_END_OBJECT ||
878
- type == WJB_BEGIN_ARRAY || type == WJB_BEGIN_OBJECT )
879
- result -> res = pushJsonbValue (& result -> parseState ,
880
- type , NULL );
881
- else
882
- result -> res = pushJsonbValue (& result -> parseState ,
883
- type , & jb );
873
+ JsonbValue * jv =
874
+ type == WJB_END_ARRAY ||
875
+ type == WJB_END_OBJECT ||
876
+ type == WJB_BEGIN_ARRAY ||
877
+ type == WJB_BEGIN_OBJECT ? NULL : & jb ;
878
+
879
+ result -> res = pushJsonbValue (& result -> parseState ,
880
+ type , jv );
884
881
}
885
882
}
886
883
}
887
- break ;
884
+ return ;
888
885
default :
889
886
outputstr = OidOutputFunctionCall (outfuncoid , val );
890
887
jb .type = jbvString ;
@@ -895,13 +892,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
895
892
}
896
893
897
894
/* Now insert jb into result, unless we did it recursively */
898
- if (!is_null && !scalar_jsonb &&
899
- tcategory >= JSONBTYPE_JSON && tcategory <= JSONBTYPE_JSONCAST )
900
- {
901
- /* work has been done recursively */
902
- return ;
903
- }
904
-
905
895
result -> res = pushScalarJsonbValue (& result -> parseState , & jb , key_scalar ,
906
896
true);
907
897
}
0 commit comments