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

Commit db40029

Browse files
author
Nikita Glukhov
committed
Implement jsonpath unary operations output
1 parent 478ad69 commit db40029

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
@@ -259,8 +259,11 @@ operationPriority(JsonPathItemType op)
259259
case jpiDiv:
260260
case jpiMod:
261261
return 4;
262-
default:
262+
case jpiPlus:
263+
case jpiMinus:
263264
return 5;
265+
default:
266+
return 6;
264267
}
265268
}
266269

@@ -327,6 +330,18 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
327330
if (printBracketes)
328331
appendStringInfoChar(buf, ')');
329332
break;
333+
case jpiPlus:
334+
case jpiMinus:
335+
if (printBracketes)
336+
appendStringInfoChar(buf, '(');
337+
appendStringInfoChar(buf, v->type == jpiPlus ? '+' : '-');
338+
jspGetArg(v, &elem);
339+
printJsonPathItem(buf, &elem, false,
340+
operationPriority(elem.type) <=
341+
operationPriority(v->type));
342+
if (printBracketes)
343+
appendStringInfoChar(buf, ')');
344+
break;
330345
case jpiFilter:
331346
appendBinaryStringInfo(buf, "?(", 2);
332347
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)