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

Commitc7372ea

Browse files
author
Nikita Glukhov
committed
Preserve json formatting in json_strip_nulls()
1 parent2798d1f commitc7372ea

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
@@ -59,7 +59,6 @@
5959
#definejsonb_populate_recordsetjson_populate_recordset
6060
#definejsonb_prettyjson_pretty
6161
#definejsonb_setjson_set
62-
#definejsonb_strip_nullsjson_strip_nulls
6362
#definejsonb_to_recordjson_to_record
6463
#definejsonb_to_recordsetjson_to_recordset
6564

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

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

508+
staticDatumjsonb_strip_nulls_internal(Jsonb*jb);
509+
508510
/*
509511
* SQL function json_object_keys
510512
*
@@ -3854,7 +3856,9 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull)
38543856
hashentry->val=_state->saved_scalar;
38553857
}
38563858
}
3859+
#endif
38573860

3861+
#ifdefJSON_C
38583862
/*
38593863
* Semantic actions for json_strip_nulls.
38603864
*
@@ -3957,12 +3961,24 @@ sn_scalar(void *state, char *token, JsonTokenType tokentype)
39573961
Datum
39583962
json_strip_nulls(PG_FUNCTION_ARGS)
39593963
{
3960-
text*json=PG_GETARG_TEXT_PP(0);
3964+
#ifdefJSON_GENERIC
3965+
Json*json=PG_GETARG_JSONB(0);
3966+
#else
3967+
text*json=PG_GETARG_TEXT_P(0);
3968+
#endif
39613969
StripnullState*state;
39623970
JsonLexContext*lex;
39633971
JsonSemAction*sem;
39643972

3973+
#ifdefJSON_GENERIC
3974+
if (json->root.ops!=&jsontContainerOps)
3975+
returnjsonb_strip_nulls_internal(json);
3976+
3977+
lex=makeJsonLexContextCstringLen(json->root.data,json->root.len, true);
3978+
#else
39653979
lex=makeJsonLexContext(json, true);
3980+
#endif
3981+
39663982
state=palloc0(sizeof(StripnullState));
39673983
sem=palloc0(sizeof(JsonSemAction));
39683984

@@ -3985,15 +4001,21 @@ json_strip_nulls(PG_FUNCTION_ARGS)
39854001
state->strval->len));
39864002

39874003
}
3988-
#endif
4004+
#else
39894005

39904006
/*
39914007
* SQL function jsonb_strip_nulls(jsonb) -> jsonb
39924008
*/
39934009
Datum
39944010
jsonb_strip_nulls(PG_FUNCTION_ARGS)
39954011
{
3996-
Jsonb*jb=PG_GETARG_JSONB(0);
4012+
returnjsonb_strip_nulls_internal(PG_GETARG_JSONB(0));
4013+
}
4014+
#endif
4015+
4016+
staticDatum
4017+
jsonb_strip_nulls_internal(Jsonb*jb)
4018+
{
39974019
JsonbIterator*it;
39984020
JsonbParseState*parseState=NULL;
39994021
JsonbValue*res=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp