Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit031b22c

Browse files
author
Nikita Glukhov
committed
Preserve json formatting in json_strip_nulls()
1 parent0a3f747 commit031b22c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

‎src/backend/utils/adt/json.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
#definejsonb_prettyjson_pretty
6363
#definejsonb_setjson_set
6464
#definejsonb_set_laxjson_set_lax
65-
#definejsonb_strip_nullsjson_strip_nulls
6665
#definejsonb_to_recordjson_to_record
6766
#definejsonb_to_recordsetjson_to_recordset
6867
#definejsonb_get_elementjson_get_element

‎src/backend/utils/adt/jsonfuncs.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ static void transform_string_values_array_element_start(void *state, bool isnull
529529
staticvoidtransform_string_values_scalar(void*state,char*token,JsonTokenTypetokentype);
530530
#endif
531531

532+
staticDatumjsonb_strip_nulls_internal(Jsonb*jb);
533+
532534
#ifndefJSON_C
533535
/*
534536
* pg_parse_json_or_ereport
@@ -4217,7 +4219,9 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull)
42174219
hashentry->val=_state->saved_scalar;
42184220
}
42194221
}
4222+
#endif
42204223

4224+
#ifdefJSON_C
42214225
/*
42224226
* Semantic actions for json_strip_nulls.
42234227
*
@@ -4320,12 +4324,24 @@ sn_scalar(void *state, char *token, JsonTokenType tokentype)
43204324
Datum
43214325
json_strip_nulls(PG_FUNCTION_ARGS)
43224326
{
4323-
text*json=PG_GETARG_TEXT_PP(0);
4327+
#ifdefJSON_GENERIC
4328+
Json*json=PG_GETARG_JSONB_P(0);
4329+
#else
4330+
text*json=PG_GETARG_TEXT_P(0);
4331+
#endif
43244332
StripnullState*state;
43254333
JsonLexContext*lex;
43264334
JsonSemAction*sem;
43274335

4336+
#ifdefJSON_GENERIC
4337+
if (json->root.ops!=&jsontContainerOps)
4338+
returnjsonb_strip_nulls_internal(json);
4339+
4340+
lex=makeJsonLexContextCstringLen(json->root.data,json->root.len,GetDatabaseEncoding(), true);
4341+
#else
43284342
lex=makeJsonLexContext(json, true);
4343+
#endif
4344+
43294345
state=palloc0(sizeof(StripnullState));
43304346
sem=palloc0(sizeof(JsonSemAction));
43314347

@@ -4348,15 +4364,21 @@ json_strip_nulls(PG_FUNCTION_ARGS)
43484364
state->strval->len));
43494365

43504366
}
4351-
#endif
4367+
#else
43524368

43534369
/*
43544370
* SQL function jsonb_strip_nulls(jsonb) -> jsonb
43554371
*/
43564372
Datum
43574373
jsonb_strip_nulls(PG_FUNCTION_ARGS)
43584374
{
4359-
Jsonb*jb=PG_GETARG_JSONB_P(0);
4375+
returnjsonb_strip_nulls_internal(PG_GETARG_JSONB_P(0));
4376+
}
4377+
#endif
4378+
4379+
staticDatum
4380+
jsonb_strip_nulls_internal(Jsonb*jb)
4381+
{
43604382
JsonbIterator*it;
43614383
JsonbParseState*parseState=NULL;
43624384
JsonbValue*res=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp