@@ -524,6 +524,8 @@ static void transform_string_values_array_element_start(void *state, bool isnull
524
524
static void transform_string_values_scalar (void * state , char * token , JsonTokenType tokentype );
525
525
#endif
526
526
527
+ static Datum jsonb_strip_nulls_internal (Jsonb * jb );
528
+
527
529
#ifndef JSON_C
528
530
/*
529
531
* pg_parse_json_or_ereport
@@ -4077,7 +4079,9 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull)
4077
4079
hashentry -> val = _state -> saved_scalar ;
4078
4080
}
4079
4081
}
4082
+ #endif
4080
4083
4084
+ #ifdef JSON_C
4081
4085
/*
4082
4086
* Semantic actions for json_strip_nulls.
4083
4087
*
@@ -4180,12 +4184,24 @@ sn_scalar(void *state, char *token, JsonTokenType tokentype)
4180
4184
Datum
4181
4185
json_strip_nulls (PG_FUNCTION_ARGS )
4182
4186
{
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
4184
4192
StripnullState * state ;
4185
4193
JsonLexContext * lex ;
4186
4194
JsonSemAction * sem ;
4187
4195
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
4188
4202
lex = makeJsonLexContext (json , true);
4203
+ #endif
4204
+
4189
4205
state = palloc0 (sizeof (StripnullState ));
4190
4206
sem = palloc0 (sizeof (JsonSemAction ));
4191
4207
@@ -4208,15 +4224,21 @@ json_strip_nulls(PG_FUNCTION_ARGS)
4208
4224
state -> strval -> len ));
4209
4225
4210
4226
}
4211
- #endif
4227
+ #else
4212
4228
4213
4229
/*
4214
4230
* SQL function jsonb_strip_nulls(jsonb) -> jsonb
4215
4231
*/
4216
4232
Datum
4217
4233
jsonb_strip_nulls (PG_FUNCTION_ARGS )
4218
4234
{
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
+ {
4220
4242
JsonbIterator * it ;
4221
4243
JsonbParseState * parseState = NULL ;
4222
4244
JsonbValue * res = NULL ;
0 commit comments