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

Commitd1ddafc

Browse files
author
Nikita Glukhov
committed
Preserve json formatting in json_strip_nulls()
1 parent161c89b commitd1ddafc

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

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

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

527+
staticDatumjsonb_strip_nulls_internal(Jsonb*jb);
528+
527529
#ifndefJSON_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+
#ifdefJSON_C
40814085
/*
40824086
* Semantic actions for json_strip_nulls.
40834087
*
@@ -4180,12 +4184,24 @@ sn_scalar(void *state, char *token, JsonTokenType tokentype)
41804184
Datum
41814185
json_strip_nulls(PG_FUNCTION_ARGS)
41824186
{
4183-
text*json=PG_GETARG_TEXT_PP(0);
4187+
#ifdefJSON_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+
#ifdefJSON_GENERIC
4197+
if (json->root.ops!=&jsontContainerOps)
4198+
returnjsonb_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
*/
42164232
Datum
42174233
jsonb_strip_nulls(PG_FUNCTION_ARGS)
42184234
{
4219-
Jsonb*jb=PG_GETARG_JSONB_P(0);
4235+
returnjsonb_strip_nulls_internal(PG_GETARG_JSONB_P(0));
4236+
}
4237+
#endif
4238+
4239+
staticDatum
4240+
jsonb_strip_nulls_internal(Jsonb*jb)
4241+
{
42204242
JsonbIterator*it;
42214243
JsonbParseState*parseState=NULL;
42224244
JsonbValue*res=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp