@@ -752,7 +752,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
752752 char * outputstr ;
753753 bool numeric_error ;
754754 JsonbValue jb ;
755- bool scalar_jsonb = false;
756755
757756 check_stack_depth ();
758757
@@ -782,10 +781,10 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
782781 {
783782 case JSONBTYPE_ARRAY :
784783 array_to_jsonb_internal (val , result );
785- break ;
784+ return ;
786785 case JSONBTYPE_COMPOSITE :
787786 composite_to_jsonb (val , result );
788- break ;
787+ return ;
789788 case JSONBTYPE_BOOL :
790789 if (key_scalar )
791790 {
@@ -881,9 +880,8 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
881880 sem .object_field_start = jsonb_in_object_field_start ;
882881
883882 pg_parse_json_or_ereport (lex , & sem );
884-
885883 }
886- break ;
884+ return ;
887885#ifdef JSON_GENERIC
888886 case JSONBTYPE_JSON :
889887#endif
@@ -905,35 +903,33 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
905903 (void ) JsonbIteratorNext (& it , & jb , true);
906904 Assert (jb .type == jbvArray );
907905 (void ) JsonbIteratorNext (& it , & jb , true);
908- scalar_jsonb = true ;
906+ break ;
909907 }
910- else
911- {
912- JsonbIteratorToken type ;
913908
914-
915- if (result -> parseState )
916- {
909+ if (result -> parseState )
910+ result -> res =
917911 pushScalarJsonbValue (& result -> parseState ,
918912 JsonToJsonValue (jsonb , & jb ),
919913 false, false);
920- return ;
921- }
914+ else
915+ {
916+ JsonbIteratorToken type ;
922917
923918 while ((type = JsonbIteratorNext (& it , & jb , false))
924919 != WJB_DONE )
925920 {
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 );
933929 }
934930 }
935931 }
936- break ;
932+ return ;
937933 default :
938934 outputstr = OidOutputFunctionCall (outfuncoid , val );
939935 jb .type = jbvString ;
@@ -944,13 +940,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
944940 }
945941
946942 /* 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-
954943 result -> res = pushScalarJsonbValue (& result -> parseState , & jb , key_scalar ,
955944 true);
956945}
0 commit comments