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

Commit 9e38a7b

Browse files
author
Nikita Glukhov
committed
Add jsonpath JsonbWrapInBinary()
1 parent e5450ba commit 9e38a7b

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
@@ -159,6 +159,17 @@ JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
159159
return jbv;
160160
}
161161

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

164175
/*
@@ -1963,7 +1974,6 @@ static inline JsonbValue *
19631974
wrapItem(JsonbValue *jbv)
19641975
{
19651976
JsonbParseState *ps = NULL;
1966-
Jsonb *jb;
19671977
JsonbValue jbvbuf;
19681978
int type = JsonbType(jbv);
19691979

@@ -1977,14 +1987,7 @@ wrapItem(JsonbValue *jbv)
19771987
pushJsonbValue(&ps, WJB_ELEM, jbv);
19781988
jbv = pushJsonbValue(&ps, WJB_END_ARRAY, NULL);
19791989

1980-
jb = JsonbValueToJsonb(jbv);
1981-
1982-
jbv = palloc(sizeof(*jbv));
1983-
jbv->type = jbvBinary;
1984-
jbv->val.binary.data = &jb->root;
1985-
jbv->val.binary.len = VARSIZE(jb) - VARHDRSZ;
1986-
1987-
return jbv;
1990+
return JsonbWrapInBinary(jbv, NULL);
19881991
}
19891992

19901993
static inline JsonPathExecResult

0 commit comments

Comments
 (0)