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

Commit 4837e2a

Browse files
feodorNikita Glukhov
authored and
Nikita Glukhov
committed
Use == instead of =
1 parent dcafedf commit 4837e2a

File tree

7 files changed

+78
-63
lines changed

7 files changed

+78
-63
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ printOperation(StringInfo buf, JsonPathItemType type)
159159
case jpiOr:
160160
appendBinaryStringInfo(buf, " || ", 4); break;
161161
case jpiEqual:
162-
appendBinaryStringInfo(buf, " = ", 3); break; /* FIXME == */
162+
appendBinaryStringInfo(buf, " == ", 4); break;
163163
case jpiNotEqual:
164164
appendBinaryStringInfo(buf, " != ", 4); break;
165165
case jpiLess:
@@ -240,8 +240,8 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
240240
break;
241241
case jpiNumeric:
242242
appendStringInfoString(buf,
243-
DatumGetCString(DirectFunctionCall1(numeric_out,
244-
PointerGetDatum(jspGetNumeric(v)))));
243+
DatumGetCString(DirectFunctionCall1(numeric_out,
244+
PointerGetDatum(jspGetNumeric(v)))));
245245
break;
246246
case jpiBool:
247247
if (jspGetBool(v))

src/backend/utils/adt/jsonpath_gram.y

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ makeAny(int first, int last)
210210
%token <str> TO_P NULL_P TRUE_P FALSE_P
211211
%token <str> STRING_P NUMERIC_P INT_P VARIABLE_P
212212
%token <str> OR_P AND_P NOT_P
213+
%token <str> LESS_P LESSEQUAL_P EQUAL_P NOTEQUAL_P GREATEREQUAL_P GREATER_P
213214
%token <str> ANY_P
214215

215216
%type <value> result jsonpath scalar_value path_primary expr
@@ -261,12 +262,12 @@ jsonpath:
261262
;
262263

263264
comp_op:
264-
'=' { $$ = jpiEqual; }
265-
| '<' '>' { $$ = jpiNotEqual; }
266-
| '<' { $$ = jpiLess; }
267-
| '>' { $$ = jpiGreater; }
268-
| '<' '=' { $$ = jpiLessOrEqual; }
269-
| '>' '=' { $$ = jpiGreaterOrEqual; }
265+
EQUAL_P { $$ = jpiEqual; }
266+
| NOTEQUAL_P { $$ = jpiNotEqual; }
267+
| LESS_P { $$ = jpiLess; }
268+
| GREATER_P { $$ = jpiGreater; }
269+
| LESSEQUAL_P { $$ = jpiLessOrEqual; }
270+
| GREATEREQUAL_P { $$ = jpiGreaterOrEqual; }
270271
;
271272

272273
delimited_predicate:

src/backend/utils/adt/jsonpath_scan.l

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ unicode \\u[0-9A-Fa-f]{4}
7979
8080
<INITIAL>\*\* { return ANY_P; }
8181
82+
<INITIAL>\< { return LESS_P; }
83+
84+
<INITIAL>\<\= { return LESSEQUAL_P; }
85+
86+
<INITIAL>\=\= { return EQUAL_P; }
87+
88+
<INITIAL>\<\> { return NOTEQUAL_P; }
89+
90+
<INITIAL>\!\= { return NOTEQUAL_P; }
91+
92+
<INITIAL>\>\= { return GREATEREQUAL_P; }
93+
94+
<INITIAL>\> { return GREATER_P; }
95+
8296
<INITIAL>\${any}+ {
8397
addstring(true, yytext + 1, yyleng - 1);
8498
addchar(false, '\0');

src/test/regress/expected/jsonb_jsonpath.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ select * from _jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[0 to 2] ? (@ < $v
220220
12
221221
(3 rows)
222222

223-
select * from _jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ = "1")');
223+
select * from _jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ == "1")');
224224
_jsonpath_query
225225
-----------------
226226
"1"
227227
(1 row)
228228

229-
select * from _jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ = $value)', '{"value" : "1"}');
229+
select * from _jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ == $value)', '{"value" : "1"}');
230230
_jsonpath_query
231231
-----------------
232232
"1"

src/test/regress/expected/jsonpath.out

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -165,58 +165,58 @@ select '$.a/+-1'::jsonpath;
165165
($."a" / -1)
166166
(1 row)
167167

168-
select '$.g ? (@ = 1)'::jsonpath;
169-
jsonpath
170-
---------------
171-
$."g"?(@ = 1)
172-
(1 row)
173-
174-
select '$.g ? (a = 1)'::jsonpath;
175-
jsonpath
176-
-----------------
177-
$."g"?("a" = 1)
168+
select '$.g ? (@ == 1)'::jsonpath;
169+
jsonpath
170+
----------------
171+
$."g"?(@ == 1)
178172
(1 row)
179173

180-
select '$.g ? (.a = 1)'::jsonpath;
181-
jsonpath
182-
-------------------
183-
$."g"?(@."a" = 1)
174+
select '$.g ? (a == 1)'::jsonpath;
175+
jsonpath
176+
------------------
177+
$."g"?("a" == 1)
184178
(1 row)
185179

186-
select '$.g ? (@.a = 1)'::jsonpath;
187-
jsonpath
188-
-------------------
189-
$."g"?(@."a" = 1)
180+
select '$.g ? (.a == 1)'::jsonpath;
181+
jsonpath
182+
--------------------
183+
$."g"?(@."a" == 1)
190184
(1 row)
191185

192-
select '$.g ? (@.a = 1 || a = 4)'::jsonpath;
193-
jsonpath
194-
------------------------------
195-
$."g"?(@."a" = 1 || "a" = 4)
186+
select '$.g ? (@.a == 1)'::jsonpath;
187+
jsonpath
188+
--------------------
189+
$."g"?(@."a" == 1)
196190
(1 row)
197191

198-
select '$.g ? (@.a = 1 && a = 4)'::jsonpath;
199-
jsonpath
200-
------------------------------
201-
$."g"?(@."a" = 1 && "a" = 4)
192+
select '$.g ? (@.a == 1 || a == 4)'::jsonpath;
193+
jsonpath
194+
--------------------------------
195+
$."g"?(@."a" == 1 || "a" == 4)
202196
(1 row)
203197

204-
select '$.g ? (@.a = 1 || a = 4 && b = 7)'::jsonpath;
205-
jsonpath
206-
-----------------------------------------
207-
$."g"?(@."a" = 1 || "a" = 4 && "b" = 7)
198+
select '$.g ? (@.a == 1 && a == 4)'::jsonpath;
199+
jsonpath
200+
--------------------------------
201+
$."g"?(@."a" == 1 && "a" == 4)
208202
(1 row)
209203

210-
select '$.g ? (@.a = 1 || !(a = 4) && b = 7)'::jsonpath;
204+
select '$.g ? (@.a == 1 || a == 4 && b == 7)'::jsonpath;
211205
jsonpath
212206
--------------------------------------------
213-
$."g"?(@."a" = 1 || !("a" = 4) && "b" = 7)
207+
$."g"?(@."a" == 1 || "a" == 4 && "b" == 7)
208+
(1 row)
209+
210+
select '$.g ? (@.a == 1 || !(a == 4) && b == 7)'::jsonpath;
211+
jsonpath
212+
-----------------------------------------------
213+
$."g"?(@."a" == 1 || !("a" == 4) && "b" == 7)
214214
(1 row)
215215

216-
select '$.g ? (@.a = 1 || !(x >= 123 || a = 4) && b = 7)'::jsonpath;
217-
jsonpath
218-
----------------------------------------------------------
219-
$."g"?(@."a" = 1 || !("x" >= 123 || "a" = 4) && "b" = 7)
216+
select '$.g ? (@.a == 1 || !(x >= 123 || a == 4) && b == 7)'::jsonpath;
217+
jsonpath
218+
-------------------------------------------------------------
219+
$."g"?(@."a" == 1 || !("x" >= 123 || "a" == 4) && "b" == 7)
220220
(1 row)
221221

222222
select '$.g ? (.x >= @[*]?(@.a > "abc"))'::jsonpath;
@@ -225,10 +225,10 @@ select '$.g ? (.x >= @[*]?(@.a > "abc"))'::jsonpath;
225225
$."g"?(@."x" >= @[*]?(@."a" > "abc"))
226226
(1 row)
227227

228-
select '$.g ? (zip = $zip)'::jsonpath;
229-
jsonpath
230-
------------------------
231-
$."g"?("zip" = $"zip")
228+
select '$.g ? (zip == $zip)'::jsonpath;
229+
jsonpath
230+
-------------------------
231+
$."g"?("zip" == $"zip")
232232
(1 row)
233233

234234
select '$.a.[1,2, 3 to 16]'::jsonpath;

src/test/regress/sql/jsonb_jsonpath.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ select * from _jsonpath_query(jsonb '{"a": 10}', '$.a ? (@ < $value)', '{"value"
3838
select * from _jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[*] ? (@ < $value)', '{"value" : 13}');
3939
select * from _jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[0,1] ? (@ < $value)', '{"value" : 13}');
4040
select * from _jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[0 to 2] ? (@ < $value)', '{"value" : 15}');
41-
select * from _jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ = "1")');
42-
select * from _jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ = $value)', '{"value" : "1"}');
41+
select * from _jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ == "1")');
42+
select * from _jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ == $value)', '{"value" : "1"}');
4343
select * from _jsonpath_query(jsonb '[1, "2", null]', '$[*] ? (@ != null)');
4444
select * from _jsonpath_query(jsonb '[1, "2", null]', '$[*] ? (@ == null)');
4545

src/test/regress/sql/jsonpath.sql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ select '$-1'::jsonpath;
2929
select '$--+1'::jsonpath;
3030
select '$.a/+-1'::jsonpath;
3131

32-
select '$.g ? (@ = 1)'::jsonpath;
33-
select '$.g ? (a = 1)'::jsonpath;
34-
select '$.g ? (.a = 1)'::jsonpath;
35-
select '$.g ? (@.a = 1)'::jsonpath;
36-
select '$.g ? (@.a = 1 || a = 4)'::jsonpath;
37-
select '$.g ? (@.a = 1 && a = 4)'::jsonpath;
38-
select '$.g ? (@.a = 1 || a = 4 && b = 7)'::jsonpath;
39-
select '$.g ? (@.a = 1 || !(a = 4) && b = 7)'::jsonpath;
40-
select '$.g ? (@.a = 1 || !(x >= 123 || a = 4) && b = 7)'::jsonpath;
32+
select '$.g ? (@ == 1)'::jsonpath;
33+
select '$.g ? (a == 1)'::jsonpath;
34+
select '$.g ? (.a == 1)'::jsonpath;
35+
select '$.g ? (@.a == 1)'::jsonpath;
36+
select '$.g ? (@.a == 1 || a == 4)'::jsonpath;
37+
select '$.g ? (@.a == 1 && a == 4)'::jsonpath;
38+
select '$.g ? (@.a == 1 || a == 4 && b == 7)'::jsonpath;
39+
select '$.g ? (@.a == 1 || !(a == 4) && b == 7)'::jsonpath;
40+
select '$.g ? (@.a == 1 || !(x >= 123 || a == 4) && b == 7)'::jsonpath;
4141
select '$.g ? (.x >= @[*]?(@.a > "abc"))'::jsonpath;
4242

43-
select '$.g ? (zip = $zip)'::jsonpath;
43+
select '$.g ? (zip == $zip)'::jsonpath;
4444
select '$.a.[1,2, 3 to 16]'::jsonpath;
4545
select '$.a[1,2, 3 to 16]'::jsonpath;
4646

0 commit comments

Comments
 (0)