Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cc71988

Browse files
author
Nikita Glukhov
committed
Add jsonpath JsonbWrapInBinary()
1 parent cf22d8f commit cc71988

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
158158
return jbv;
159159
}
160160

161+
static inline JsonbValue *
162+
JsonbWrapInBinary(JsonbValue *jbv, JsonbValue *out)
163+
{
164+
Jsonb *jb = JsonbValueToJsonb(jbv);
165+
166+
if (!out)
167+
out = palloc(sizeof(*out));
168+
169+
return JsonbInitBinary(out, jb);
170+
}
171+
161172
/********************Execute functions for JsonPath***************************/
162173

163174
/*
@@ -1792,7 +1803,6 @@ static inline JsonbValue *
17921803
wrapItem(JsonbValue *jbv)
17931804
{
17941805
JsonbParseState *ps = NULL;
1795-
Jsonb *jb;
17961806
JsonbValue jbvbuf;
17971807
int type = JsonbType(jbv);
17981808

@@ -1806,14 +1816,7 @@ wrapItem(JsonbValue *jbv)
18061816
pushJsonbValue(&ps, WJB_ELEM, jbv);
18071817
jbv = pushJsonbValue(&ps, WJB_END_ARRAY, NULL);
18081818

1809-
jb = JsonbValueToJsonb(jbv);
1810-
1811-
jbv = palloc(sizeof(*jbv));
1812-
jbv->type = jbvBinary;
1813-
jbv->val.binary.data = &jb->root;
1814-
jbv->val.binary.len = VARSIZE(jb) - VARHDRSZ;
1815-
1816-
return jbv;
1819+
return JsonbWrapInBinary(jbv, NULL);
18171820
}
18181821

18191822
static inline JsonPathExecResult

0 commit comments

Comments
 (0)