@@ -529,6 +529,8 @@ static void transform_string_values_array_element_start(void *state, bool isnull
529
529
static void transform_string_values_scalar (void * state , char * token , JsonTokenType tokentype );
530
530
#endif
531
531
532
+ static Datum jsonb_strip_nulls_internal (Jsonb * jb );
533
+
532
534
#ifndef JSON_C
533
535
/*
534
536
* pg_parse_json_or_ereport
@@ -4217,7 +4219,9 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull)
4217
4219
hashentry -> val = _state -> saved_scalar ;
4218
4220
}
4219
4221
}
4222
+ #endif
4220
4223
4224
+ #ifdef JSON_C
4221
4225
/*
4222
4226
* Semantic actions for json_strip_nulls.
4223
4227
*
@@ -4320,12 +4324,24 @@ sn_scalar(void *state, char *token, JsonTokenType tokentype)
4320
4324
Datum
4321
4325
json_strip_nulls (PG_FUNCTION_ARGS )
4322
4326
{
4323
- text * json = PG_GETARG_TEXT_PP (0 );
4327
+ #ifdef JSON_GENERIC
4328
+ Json * json = PG_GETARG_JSONB_P (0 );
4329
+ #else
4330
+ text * json = PG_GETARG_TEXT_P (0 );
4331
+ #endif
4324
4332
StripnullState * state ;
4325
4333
JsonLexContext * lex ;
4326
4334
JsonSemAction * sem ;
4327
4335
4336
+ #ifdef JSON_GENERIC
4337
+ if (json -> root .ops != & jsontContainerOps )
4338
+ return jsonb_strip_nulls_internal (json );
4339
+
4340
+ lex = makeJsonLexContextCstringLen (json -> root .data , json -> root .len , GetDatabaseEncoding (), true);
4341
+ #else
4328
4342
lex = makeJsonLexContext (json , true);
4343
+ #endif
4344
+
4329
4345
state = palloc0 (sizeof (StripnullState ));
4330
4346
sem = palloc0 (sizeof (JsonSemAction ));
4331
4347
@@ -4348,15 +4364,21 @@ json_strip_nulls(PG_FUNCTION_ARGS)
4348
4364
state -> strval -> len ));
4349
4365
4350
4366
}
4351
- #endif
4367
+ #else
4352
4368
4353
4369
/*
4354
4370
* SQL function jsonb_strip_nulls(jsonb) -> jsonb
4355
4371
*/
4356
4372
Datum
4357
4373
jsonb_strip_nulls (PG_FUNCTION_ARGS )
4358
4374
{
4359
- Jsonb * jb = PG_GETARG_JSONB_P (0 );
4375
+ return jsonb_strip_nulls_internal (PG_GETARG_JSONB_P (0 ));
4376
+ }
4377
+ #endif
4378
+
4379
+ static Datum
4380
+ jsonb_strip_nulls_internal (Jsonb * jb )
4381
+ {
4360
4382
JsonbIterator * it ;
4361
4383
JsonbParseState * parseState = NULL ;
4362
4384
JsonbValue * res = NULL ;
0 commit comments