@@ -752,7 +752,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
752
752
char * outputstr ;
753
753
bool numeric_error ;
754
754
JsonbValue jb ;
755
- bool scalar_jsonb = false;
756
755
757
756
check_stack_depth ();
758
757
@@ -782,10 +781,10 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
782
781
{
783
782
case JSONBTYPE_ARRAY :
784
783
array_to_jsonb_internal (val ,result );
785
- break ;
784
+ return ;
786
785
case JSONBTYPE_COMPOSITE :
787
786
composite_to_jsonb (val ,result );
788
- break ;
787
+ return ;
789
788
case JSONBTYPE_BOOL :
790
789
if (key_scalar )
791
790
{
@@ -881,9 +880,8 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
881
880
sem .object_field_start = jsonb_in_object_field_start ;
882
881
883
882
pg_parse_json_or_ereport (lex ,& sem );
884
-
885
883
}
886
- break ;
884
+ return ;
887
885
#ifdef JSON_GENERIC
888
886
case JSONBTYPE_JSON :
889
887
#endif
@@ -905,35 +903,33 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
905
903
(void )JsonbIteratorNext (& it ,& jb , true);
906
904
Assert (jb .type == jbvArray );
907
905
(void )JsonbIteratorNext (& it ,& jb , true);
908
- scalar_jsonb = true ;
906
+ break ;
909
907
}
910
- else
911
- {
912
- JsonbIteratorToken type ;
913
908
914
-
915
- if (result -> parseState )
916
- {
909
+ if (result -> parseState )
910
+ result -> res =
917
911
pushScalarJsonbValue (& result -> parseState ,
918
912
JsonToJsonValue (jsonb ,& jb ),
919
913
false, false);
920
- return ;
921
- }
914
+ else
915
+ {
916
+ JsonbIteratorToken type ;
922
917
923
918
while ((type = JsonbIteratorNext (& it ,& jb , false))
924
919
!= WJB_DONE )
925
920
{
926
- if (type == WJB_END_ARRAY || type == WJB_END_OBJECT ||
927
- type == WJB_BEGIN_ARRAY || type == WJB_BEGIN_OBJECT )
928
- result -> res = pushJsonbValue (& result -> parseState ,
929
- type ,NULL );
930
- else
931
- result -> res = pushJsonbValue (& result -> parseState ,
932
- type ,& jb );
921
+ JsonbValue * jv =
922
+ type == WJB_END_ARRAY ||
923
+ type == WJB_END_OBJECT ||
924
+ type == WJB_BEGIN_ARRAY ||
925
+ type == WJB_BEGIN_OBJECT ?NULL :& jb ;
926
+
927
+ result -> res = pushJsonbValue (& result -> parseState ,
928
+ type ,jv );
933
929
}
934
930
}
935
931
}
936
- break ;
932
+ return ;
937
933
default :
938
934
outputstr = OidOutputFunctionCall (outfuncoid ,val );
939
935
jb .type = jbvString ;
@@ -944,13 +940,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
944
940
}
945
941
946
942
/* Now insert jb into result, unless we did it recursively */
947
- if (!is_null && !scalar_jsonb &&
948
- tcategory >=JSONBTYPE_JSON && tcategory <=JSONBTYPE_JSONCAST )
949
- {
950
- /* work has been done recursively */
951
- return ;
952
- }
953
-
954
943
result -> res = pushScalarJsonbValue (& result -> parseState ,& jb ,key_scalar ,
955
944
true);
956
945
}