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

Commit da4bc85

Browse files
author
Nikita Glukhov
committed
Implement jsonpath unary operations output
1 parent fdac827 commit da4bc85

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,11 @@ operationPriority(JsonPathItemType op)
255255
case jpiDiv:
256256
case jpiMod:
257257
return 4;
258-
default:
258+
case jpiPlus:
259+
case jpiMinus:
259260
return 5;
261+
default:
262+
return 6;
260263
}
261264
}
262265

@@ -323,6 +326,18 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
323326
if (printBracketes)
324327
appendStringInfoChar(buf, ')');
325328
break;
329+
case jpiPlus:
330+
case jpiMinus:
331+
if (printBracketes)
332+
appendStringInfoChar(buf, '(');
333+
appendStringInfoChar(buf, v->type == jpiPlus ? '+' : '-');
334+
jspGetArg(v, &elem);
335+
printJsonPathItem(buf, &elem, false,
336+
operationPriority(elem.type) <=
337+
operationPriority(v->type));
338+
if (printBracketes)
339+
appendStringInfoChar(buf, ')');
340+
break;
326341
case jpiFilter:
327342
appendBinaryStringInfo(buf, "?(", 2);
328343
jspGetArg(v, &elem);

src/test/regress/expected/jsonpath.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ select '$.g ? ((x >= 123 || a == 4) && exists (.x ? (@ == 14)))'::jsonpath;
263263
$."g"?(("x" >= 123 || "a" == 4) && exists (@."x"?(@ == 14)))
264264
(1 row)
265265

266+
select '$.g ? (+x >= +-(+a + 2))'::jsonpath;
267+
jsonpath
268+
--------------------------------
269+
$."g"?(+"x" >= +(-(+"a" + 2)))
270+
(1 row)
271+
266272
select '$a'::jsonpath;
267273
jsonpath
268274
----------

src/test/regress/sql/jsonpath.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ select '$.g ? (exists (.x))'::jsonpath;
4545
select '$.g ? (exists (@.x ? (@ == 14)))'::jsonpath;
4646
select '$.g ? (exists (.x ? (@ == 14)))'::jsonpath;
4747
select '$.g ? ((x >= 123 || a == 4) && exists (.x ? (@ == 14)))'::jsonpath;
48+
select '$.g ? (+x >= +-(+a + 2))'::jsonpath;
4849

4950
select '$a'::jsonpath;
5051
select '$a.b'::jsonpath;

0 commit comments

Comments
 (0)