@@ -700,7 +700,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
700
700
char * outputstr ;
701
701
bool numeric_error ;
702
702
JsonbValue jb ;
703
- bool scalar_jsonb = false;
704
703
705
704
check_stack_depth ();
706
705
@@ -730,10 +729,10 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
730
729
{
731
730
case JSONBTYPE_ARRAY :
732
731
array_to_jsonb_internal (val ,result );
733
- break ;
732
+ return ;
734
733
case JSONBTYPE_COMPOSITE :
735
734
composite_to_jsonb (val ,result );
736
- break ;
735
+ return ;
737
736
case JSONBTYPE_BOOL :
738
737
if (key_scalar )
739
738
{
@@ -873,9 +872,8 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
873
872
sem .object_field_start = jsonb_in_object_field_start ;
874
873
875
874
pg_parse_json (lex ,& sem );
876
-
877
875
}
878
- break ;
876
+ return ;
879
877
#ifdef JSON_GENERIC
880
878
case JSONBTYPE_JSON :
881
879
#endif
@@ -897,35 +895,33 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
897
895
(void )JsonbIteratorNext (& it ,& jb , true);
898
896
Assert (jb .type == jbvArray );
899
897
(void )JsonbIteratorNext (& it ,& jb , true);
900
- scalar_jsonb = true ;
898
+ break ;
901
899
}
902
- else
903
- {
904
- JsonbIteratorToken type ;
905
900
906
-
907
- if (result -> parseState )
908
- {
901
+ if (result -> parseState )
902
+ result -> res =
909
903
pushScalarJsonbValue (& result -> parseState ,
910
904
JsonToJsonValue (jsonb ,& jb ),
911
905
false, false);
912
- return ;
913
- }
906
+ else
907
+ {
908
+ JsonbIteratorToken type ;
914
909
915
910
while ((type = JsonbIteratorNext (& it ,& jb , false))
916
911
!= WJB_DONE )
917
912
{
918
- if (type == WJB_END_ARRAY || type == WJB_END_OBJECT ||
919
- type == WJB_BEGIN_ARRAY || type == WJB_BEGIN_OBJECT )
920
- result -> res = pushJsonbValue (& result -> parseState ,
921
- type ,NULL );
922
- else
923
- result -> res = pushJsonbValue (& result -> parseState ,
924
- type ,& jb );
913
+ JsonbValue * jv =
914
+ type == WJB_END_ARRAY ||
915
+ type == WJB_END_OBJECT ||
916
+ type == WJB_BEGIN_ARRAY ||
917
+ type == WJB_BEGIN_OBJECT ?NULL :& jb ;
918
+
919
+ result -> res = pushJsonbValue (& result -> parseState ,
920
+ type ,jv );
925
921
}
926
922
}
927
923
}
928
- break ;
924
+ return ;
929
925
default :
930
926
outputstr = OidOutputFunctionCall (outfuncoid ,val );
931
927
jb .type = jbvString ;
@@ -936,13 +932,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
936
932
}
937
933
938
934
/* Now insert jb into result, unless we did it recursively */
939
- if (!is_null && !scalar_jsonb &&
940
- tcategory >=JSONBTYPE_JSON && tcategory <=JSONBTYPE_JSONCAST )
941
- {
942
- /* work has been done recursively */
943
- return ;
944
- }
945
-
946
935
result -> res = pushScalarJsonbValue (& result -> parseState ,& jb ,key_scalar ,
947
936
true);
948
937
}