@@ -505,6 +505,8 @@ static void transform_string_values_array_element_start(void *state, bool isnull
505
505
static void transform_string_values_scalar (void * state , char * token , JsonTokenType tokentype );
506
506
#endif
507
507
508
+ static Datum jsonb_strip_nulls_internal (Jsonb * jb );
509
+
508
510
/*
509
511
* SQL function json_object_keys
510
512
*
@@ -3854,7 +3856,9 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull)
3854
3856
hashentry -> val = _state -> saved_scalar ;
3855
3857
}
3856
3858
}
3859
+ #endif
3857
3860
3861
+ #ifdef JSON_C
3858
3862
/*
3859
3863
* Semantic actions for json_strip_nulls.
3860
3864
*
@@ -3957,12 +3961,24 @@ sn_scalar(void *state, char *token, JsonTokenType tokentype)
3957
3961
Datum
3958
3962
json_strip_nulls (PG_FUNCTION_ARGS )
3959
3963
{
3960
- text * json = PG_GETARG_TEXT_PP (0 );
3964
+ #ifdef JSON_GENERIC
3965
+ Json * json = PG_GETARG_JSONB (0 );
3966
+ #else
3967
+ text * json = PG_GETARG_TEXT_P (0 );
3968
+ #endif
3961
3969
StripnullState * state ;
3962
3970
JsonLexContext * lex ;
3963
3971
JsonSemAction * sem ;
3964
3972
3973
+ #ifdef JSON_GENERIC
3974
+ if (json -> root .ops != & jsontContainerOps )
3975
+ return jsonb_strip_nulls_internal (json );
3976
+
3977
+ lex = makeJsonLexContextCstringLen (json -> root .data , json -> root .len , true);
3978
+ #else
3965
3979
lex = makeJsonLexContext (json , true);
3980
+ #endif
3981
+
3966
3982
state = palloc0 (sizeof (StripnullState ));
3967
3983
sem = palloc0 (sizeof (JsonSemAction ));
3968
3984
@@ -3985,15 +4001,21 @@ json_strip_nulls(PG_FUNCTION_ARGS)
3985
4001
state -> strval -> len ));
3986
4002
3987
4003
}
3988
- #endif
4004
+ #else
3989
4005
3990
4006
/*
3991
4007
* SQL function jsonb_strip_nulls(jsonb) -> jsonb
3992
4008
*/
3993
4009
Datum
3994
4010
jsonb_strip_nulls (PG_FUNCTION_ARGS )
3995
4011
{
3996
- Jsonb * jb = PG_GETARG_JSONB (0 );
4012
+ return jsonb_strip_nulls_internal (PG_GETARG_JSONB (0 ));
4013
+ }
4014
+ #endif
4015
+
4016
+ static Datum
4017
+ jsonb_strip_nulls_internal (Jsonb * jb )
4018
+ {
3997
4019
JsonbIterator * it ;
3998
4020
JsonbParseState * parseState = NULL ;
3999
4021
JsonbValue * res = NULL ;
0 commit comments