@@ -716,7 +716,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
716716 char * outputstr ;
717717 bool numeric_error ;
718718 JsonbValue jb ;
719- bool scalar_jsonb = false;
720719
721720 check_stack_depth ();
722721
@@ -746,10 +745,10 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
746745 {
747746 case JSONBTYPE_ARRAY :
748747 array_to_jsonb_internal (val , result );
749- break ;
748+ return ;
750749 case JSONBTYPE_COMPOSITE :
751750 composite_to_jsonb (val , result );
752- break ;
751+ return ;
753752 case JSONBTYPE_BOOL :
754753 if (key_scalar )
755754 {
@@ -843,7 +842,7 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
843842
844843 pg_parse_json_or_ereport (lex , & sem );
845844 }
846- break ;
845+ return ;
847846 case JSONBTYPE_JSONB :
848847 {
849848 Jsonb * jsonb = DatumGetJsonbP (val );
@@ -856,35 +855,33 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
856855 (void ) JsonbIteratorNext (& it , & jb , true);
857856 Assert (jb .type == jbvArray );
858857 (void ) JsonbIteratorNext (& it , & jb , true);
859- scalar_jsonb = true ;
858+ break ;
860859 }
861- else
862- {
863- JsonbIteratorToken type ;
864-
865860
866- if (result -> parseState )
867- {
861+ if (result -> parseState )
862+ result -> res =
868863 pushScalarJsonbValue (& result -> parseState ,
869864 JsonToJsonValue (jsonb , & jb ),
870865 false, false);
871- return ;
872- }
866+ else
867+ {
868+ JsonbIteratorToken type ;
873869
874870 while ((type = JsonbIteratorNext (& it , & jb , false))
875871 != WJB_DONE )
876872 {
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 );
884881 }
885882 }
886883 }
887- break ;
884+ return ;
888885 default :
889886 outputstr = OidOutputFunctionCall (outfuncoid , val );
890887 jb .type = jbvString ;
@@ -895,13 +892,6 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
895892 }
896893
897894 /* 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-
905895 result -> res = pushScalarJsonbValue (& result -> parseState , & jb , key_scalar ,
906896 true);
907897}
0 commit comments