@@ -524,6 +524,8 @@ static void transform_string_values_array_element_start(void *state, bool isnull
524524static void transform_string_values_scalar (void * state , char * token , JsonTokenType tokentype );
525525#endif
526526
527+ static Datum jsonb_strip_nulls_internal (Jsonb * jb );
528+
527529#ifndef JSON_C
528530/*
529531 * pg_parse_json_or_ereport
@@ -4077,7 +4079,9 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull)
40774079 hashentry -> val = _state -> saved_scalar ;
40784080 }
40794081}
4082+ #endif
40804083
4084+ #ifdef JSON_C
40814085/*
40824086 * Semantic actions for json_strip_nulls.
40834087 *
@@ -4180,12 +4184,24 @@ sn_scalar(void *state, char *token, JsonTokenType tokentype)
41804184Datum
41814185json_strip_nulls (PG_FUNCTION_ARGS )
41824186{
4183- text * json = PG_GETARG_TEXT_PP (0 );
4187+ #ifdef JSON_GENERIC
4188+ Json * json = PG_GETARG_JSONB_P (0 );
4189+ #else
4190+ text * json = PG_GETARG_TEXT_P (0 );
4191+ #endif
41844192 StripnullState * state ;
41854193 JsonLexContext * lex ;
41864194 JsonSemAction * sem ;
41874195
4196+ #ifdef JSON_GENERIC
4197+ if (json -> root .ops != & jsontContainerOps )
4198+ return jsonb_strip_nulls_internal (json );
4199+
4200+ lex = makeJsonLexContextCstringLen (json -> root .data , json -> root .len , GetDatabaseEncoding (), true);
4201+ #else
41884202 lex = makeJsonLexContext (json , true);
4203+ #endif
4204+
41894205 state = palloc0 (sizeof (StripnullState ));
41904206 sem = palloc0 (sizeof (JsonSemAction ));
41914207
@@ -4208,15 +4224,21 @@ json_strip_nulls(PG_FUNCTION_ARGS)
42084224 state -> strval -> len ));
42094225
42104226}
4211- #endif
4227+ #else
42124228
42134229/*
42144230 * SQL function jsonb_strip_nulls(jsonb) -> jsonb
42154231 */
42164232Datum
42174233jsonb_strip_nulls (PG_FUNCTION_ARGS )
42184234{
4219- Jsonb * jb = PG_GETARG_JSONB_P (0 );
4235+ return jsonb_strip_nulls_internal (PG_GETARG_JSONB_P (0 ));
4236+ }
4237+ #endif
4238+
4239+ static Datum
4240+ jsonb_strip_nulls_internal (Jsonb * jb )
4241+ {
42204242 JsonbIterator * it ;
42214243 JsonbParseState * parseState = NULL ;
42224244 JsonbValue * res = NULL ;
0 commit comments