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

Commite080b22

Browse files
author
Nikita Glukhov
committed
Add GSON method setPath()
1 parent78c9dbc commite080b22

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

‎contrib/jsonb_toaster/jsonb_toaster.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,14 @@ jsonxzCopy(JsonContainer *jc)
20612061
returnres;
20622062
}
20632063

2064+
staticDatum
2065+
jsonxSetPath(JsonContainer*js,Datum*path_elems,
2066+
bool*path_nulls,intpath_len,
2067+
JsonValue*newval,intflags)
2068+
{
2069+
returnJsonSetPathGeneric(js,path_elems,path_nulls,path_len,newval,flags);
2070+
}
2071+
20642072
staticJsonContainerOps
20652073
jsonxzContainerOps=
20662074
{
@@ -2074,7 +2082,8 @@ jsonxzContainerOps =
20742082
JsonbToCStringRaw,
20752083
jsonxzCopy,
20762084
jsonxzFree,
2077-
jsonxzEncode
2085+
jsonxzEncode,
2086+
jsonxSetPath
20782087
};
20792088

20802089
staticJsonContainerOps
@@ -2090,7 +2099,8 @@ jsonxContainerOps =
20902099
JsonbToCStringRaw,
20912100
JsonCopyFlat,
20922101
NULL,
2093-
jsonxEncode
2102+
jsonxEncode,
2103+
jsonxSetPath
20942104
};
20952105

20962106
staticJsonContainer*

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,7 +2578,8 @@ jsonbContainerOps =
25782578
JsonbToCStringRaw,
25792579
JsonCopyFlat,
25802580
NULL,
2581-
NULL
2581+
NULL,
2582+
JsonSetPathGeneric
25822583
};
25832584

25842585
#ifndefJSONB_DETOAST_ITERATOR
@@ -3169,7 +3170,8 @@ jsonbzContainerOps =
31693170
JsonbToCStringRaw,
31703171
JsonCopyFlat,// FIXME
31713172
jsonbzFree,
3172-
NULL
3173+
NULL,
3174+
JsonSetPathGeneric
31733175
};
31743176

31753177
Json*

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4532,6 +4532,23 @@ jsonb_delete_idx(PG_FUNCTION_ARGS)
45324532
PG_RETURN_DATUM(JsonbValueToOrigJsonbDatum(res,in));
45334533
}
45344534

4535+
Datum
4536+
JsonSetPathGeneric(JsonContainer*js,
4537+
Datum*path_elems,bool*path_nulls,intpath_len,
4538+
JsonValue*newval,intflags)
4539+
{
4540+
JsonbParseState*st=NULL;
4541+
JsonbIterator*it=JsonbIteratorInit(js);
4542+
JsonbValue*res;
4543+
4544+
res=setPath(&it,path_elems,path_nulls,path_len,&st,0,
4545+
newval,flags);
4546+
4547+
Assert(res!=NULL);
4548+
4549+
returnJsonbValueToOrigJsonbDatum2(res,js);
4550+
}
4551+
45354552
/*
45364553
* SQL function jsonb_set(jsonb, text[], jsonb, boolean)
45374554
*/
@@ -4543,12 +4560,10 @@ jsonb_set(PG_FUNCTION_ARGS)
45434560
Jsonb*newjsonb=PG_GETARG_JSONB_P(2);
45444561
JsonbValuenewval;
45454562
boolcreate=PG_GETARG_BOOL(3);
4546-
JsonbValue*res=NULL;
4563+
Datumres;
45474564
Datum*path_elems;
45484565
bool*path_nulls;
45494566
intpath_len;
4550-
JsonbIterator*it;
4551-
JsonbParseState*st=NULL;
45524567

45534568
JsonToJsonValue(newjsonb,&newval);
45544569

@@ -4570,14 +4585,10 @@ jsonb_set(PG_FUNCTION_ARGS)
45704585
if (path_len==0)
45714586
PG_RETURN_JSONB_P(in);
45724587

4573-
it=JsonbIteratorInit(JsonbRoot(in));
4574-
4575-
res=setPath(&it,path_elems,path_nulls,path_len,&st,
4576-
0,&newval,create ?JB_PATH_CREATE :JB_PATH_REPLACE);
4577-
4578-
Assert(res!=NULL);
4588+
res=JsonSetPath(JsonbRoot(in),path_elems,path_nulls,path_len,
4589+
&newval,create ?JB_PATH_CREATE :JB_PATH_REPLACE);
45794590

4580-
PG_RETURN_DATUM(JsonbValueToOrigJsonbDatum(res,in));
4591+
PG_RETURN_DATUM(res);
45814592
}
45824593

45834594

‎src/include/utils/json_generic.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ struct JsonContainerOps
7474
JsonContainer*(*copy)(JsonContainer*jc);
7575
void(*free)(JsonContainer*jc);
7676
void*(*encode)(JsonValue*jc,JsonContainerOps*ops,Oidtoasterid);
77+
Datum(*setPath)(JsonContainer*js,Datum*path_elems,
78+
bool*path_nulls,intpath_len,
79+
JsonValue*newval,intflags);
7780
};
7881

7982
typedefstructCompressedObject
@@ -166,6 +169,9 @@ typedef JsonContainer JsonbContainer;
166169
#defineJsonOp4(op,jscontainer,arg1,arg2,arg3,arg4) \
167170
JsonOp(op, jscontainer)(jscontainer, arg1, arg2, arg3, arg4)
168171

172+
#defineJsonOp5(op,jscontainer,arg1,arg2,arg3,arg4,arg5) \
173+
JsonOp(op, jscontainer)(jscontainer, arg1, arg2, arg3, arg4, arg5)
174+
169175
#defineJsonIteratorInit(jscontainer) \
170176
JsonOp0(iteratorInit, jscontainer)
171177

@@ -195,6 +201,8 @@ typedef JsonContainer JsonbContainer;
195201
(jc)->ops->free(jc); \
196202
} while (0)
197203

204+
#defineJsonSetPath(jc,path_elems,path_nulls,path_len,newval,flags) \
205+
JsonOp5(setPath, jc, path_elems, path_nulls, path_len, newval, flags)
198206

199207
staticinlineJsonIteratorToken
200208
JsonIteratorNext(JsonIterator**it,JsonValue*val,boolskipNested)
@@ -303,6 +311,9 @@ extern JsonValue *JsonValueCopy(JsonValue *res, const JsonValue *val);
303311
externconstJsonValue*JsonValueUnwrap(constJsonValue*val,JsonValue*buf);
304312
externJsonContainer*JsonCopyFlat(JsonContainer*flatContainer);
305313
externJsonValue*JsonExtractScalar(JsonContainer*jc,JsonValue*scalar);
314+
externDatumJsonSetPathGeneric(JsonContainer*js,Datum*path_elems,
315+
bool*path_nulls,intpath_len,
316+
JsonValue*newval,intflags);
306317

307318
externJsonb*JsonbMakeEmptyArray(void);
308319
externJsonb*JsonbMakeEmptyObject(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp