Skip to content

Commit 71c25d7

Browse files
author
Nikita Glukhov
committed
Simplify jsonb_get_element()
1 parent 8b36bda commit 71c25d7

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/backend/utils/adt/jsonfuncs.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,33 +4012,23 @@ Datum
40124012
jsonb_get_element(Datum jsonbdatum, text **path, int path_len, bool *is_null)
40134013
{
40144014
Jsonb *jb = DatumGetJsonb(jsonbdatum);
4015-
JsonbValue *v;
4016-
int level = 1;
4015+
JsonbValue vbuf;
4016+
JsonbValue *v = JsonbToJsonbValue(jb, &vbuf);
4017+
int level;
40174018

4018-
if (!JB_ROOT_IS_OBJECT(jb))
4019+
for (level = 0; level < path_len; level++)
40194020
{
4020-
*is_null = true;
4021-
return (Datum) 0;
4022-
}
4023-
4024-
v = findJsonbValueFromContainerLen(&jb->root, JB_FOBJECT,
4025-
VARDATA_ANY(path[0]),
4026-
VARSIZE_ANY_EXHDR(path[0]));
4027-
4028-
while (v != NULL &&
4029-
v->type == jbvBinary && level < path_len)
4030-
{
4031-
v = findJsonbValueFromContainerLen(v->val.binary.data, JB_FOBJECT,
4032-
VARDATA_ANY(path[level]),
4033-
VARSIZE_ANY_EXHDR(path[level]));
4034-
level++;
4021+
if (v->type != jbvBinary ||
4022+
!(v = findJsonbValueFromContainerLen(v->val.binary.data, JB_FOBJECT,
4023+
VARDATA_ANY(path[level]),
4024+
VARSIZE_ANY_EXHDR(path[level]))))
4025+
{
4026+
*is_null = true;
4027+
return (Datum) 0;
4028+
}
40354029
}
40364030

4037-
if (v != NULL && level == path_len)
4038-
PG_RETURN_JSONB(JsonbValueToJsonb(v));
4039-
4040-
*is_null = true;
4041-
return (Datum) 0;
4031+
PG_RETURN_JSONB(JsonbValueToJsonb(v));
40424032
}
40434033

40444034
Datum

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy