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

Commit 47646a9

Browse files
author
Nikita Glukhov
committed
Implement jsonpath unary operations output
1 parent 515e8e7 commit 47646a9

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
@@ -267,6 +267,12 @@ select '$.g ? ((x >= 123 || a == 4) && exists (.x ? (@ == 14)))'::jsonpath;
267267
$."g"?(("x" >= 123 || "a" == 4) && exists (@."x"?(@ == 14)))
268268
(1 row)
269269

270+
select '$.g ? (+x >= +-(+a + 2))'::jsonpath;
271+
jsonpath
272+
--------------------------------
273+
$."g"?(+"x" >= +(-(+"a" + 2)))
274+
(1 row)
275+
270276
select '$a'::jsonpath;
271277
jsonpath
272278
----------

src/test/regress/sql/jsonpath.sql

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

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

0 commit comments

Comments
 (0)