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

Commit 9cad7ae

Browse files
author
Nikita Glukhov
committed
Fix jsonpath array accessor syntax
1 parent e052526 commit 9cad7ae

File tree

5 files changed

+46
-89
lines changed

5 files changed

+46
-89
lines changed

src/backend/utils/adt/jsonpath_gram.y

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ accessor_op:
431431
'.' key { $$ = $2; }
432432
| '.' '*' { $$ = makeItemType(jpiAnyKey); }
433433
| array_accessor { $$ = $1; }
434-
| '.' array_accessor { $$ = $2; }
435434
| '.' any_path { $$ = $2; }
436435
| '.' method '(' ')' { $$ = makeItemType($2); }
437436
| '.' DATETIME_P '(' opt_datetime_template ')'

src/test/regress/expected/jsonb_jsonpath.out

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,63 +58,63 @@ select jsonb '{"a": {"b": 1}}' @? 'lax $.**{3}';
5858
f
5959
(1 row)
6060

61-
select jsonb '[]' @? '$.[*]';
61+
select jsonb '[]' @? '$[*]';
6262
?column?
6363
----------
6464
f
6565
(1 row)
6666

67-
select jsonb '[1]' @? '$.[*]';
67+
select jsonb '[1]' @? '$[*]';
6868
?column?
6969
----------
7070
t
7171
(1 row)
7272

73-
select jsonb '[1]' @? '$.[1]';
73+
select jsonb '[1]' @? '$[1]';
7474
?column?
7575
----------
7676
f
7777
(1 row)
7878

79-
select jsonb '[1]' @? 'strict $.[1]';
79+
select jsonb '[1]' @? 'strict $[1]';
8080
?column?
8181
----------
8282

8383
(1 row)
8484

8585
select jsonb '[1]' @* 'strict $[1]';
8686
ERROR: Invalid SQL/JSON subscript
87-
select jsonb '[1]' @? '$.[0]';
87+
select jsonb '[1]' @? '$[0]';
8888
?column?
8989
----------
9090
t
9191
(1 row)
9292

93-
select jsonb '[1]' @? '$.[0.3]';
93+
select jsonb '[1]' @? '$[0.3]';
9494
?column?
9595
----------
9696
t
9797
(1 row)
9898

99-
select jsonb '[1]' @? '$.[0.5]';
99+
select jsonb '[1]' @? '$[0.5]';
100100
?column?
101101
----------
102102
t
103103
(1 row)
104104

105-
select jsonb '[1]' @? '$.[0.9]';
105+
select jsonb '[1]' @? '$[0.9]';
106106
?column?
107107
----------
108108
t
109109
(1 row)
110110

111-
select jsonb '[1]' @? '$.[1.2]';
111+
select jsonb '[1]' @? '$[1.2]';
112112
?column?
113113
----------
114114
f
115115
(1 row)
116116

117-
select jsonb '[1]' @? 'strict $.[1.2]';
117+
select jsonb '[1]' @? 'strict $[1.2]';
118118
?column?
119119
----------
120120

@@ -193,48 +193,48 @@ select jsonb '{"a": 12, "b": {"a": 13}}' @* 'lax $.*.a';
193193
13
194194
(1 row)
195195

196-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[*].a';
196+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[*].a';
197197
?column?
198198
----------
199199
13
200200
(1 row)
201201

202-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[*].*';
202+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[*].*';
203203
?column?
204204
----------
205205
13
206206
14
207207
(2 rows)
208208

209-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[0].a';
209+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[0].a';
210210
?column?
211211
----------
212212
(0 rows)
213213

214-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[1].a';
214+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[1].a';
215215
?column?
216216
----------
217217
13
218218
(1 row)
219219

220-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[2].a';
220+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[2].a';
221221
?column?
222222
----------
223223
(0 rows)
224224

225-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[0,1].a';
225+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[0,1].a';
226226
?column?
227227
----------
228228
13
229229
(1 row)
230230

231-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[0 to 10].a';
231+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[0 to 10].a';
232232
?column?
233233
----------
234234
13
235235
(1 row)
236236

237-
select jsonb '[12, {"a": 13}, {"b": 14}, "ccc", true]' @* '$.[2.5 - 1 to @.size() - 2]';
237+
select jsonb '[12, {"a": 13}, {"b": 14}, "ccc", true]' @* '$[2.5 - 1 to @.size() - 2]';
238238
?column?
239239
-----------
240240
{"a": 13}
@@ -332,36 +332,36 @@ select * from jsonpath_query(jsonb '{"a": 10}', '$.a ? (@ < $value)', '{"value"
332332
10
333333
(1 row)
334334

335-
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[*] ? (@ < $value)', '{"value" : 13}');
335+
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$[*] ? (@ < $value)', '{"value" : 13}');
336336
jsonpath_query
337337
----------------
338338
10
339339
11
340340
12
341341
(3 rows)
342342

343-
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[0,1] ? (@ < $value)', '{"value" : 13}');
343+
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$[0,1] ? (@ < $value)', '{"value" : 13}');
344344
jsonpath_query
345345
----------------
346346
10
347347
11
348348
(2 rows)
349349

350-
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[0 to 2] ? (@ < $value)', '{"value" : 15}');
350+
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$[0 to 2] ? (@ < $value)', '{"value" : 15}');
351351
jsonpath_query
352352
----------------
353353
10
354354
11
355355
12
356356
(3 rows)
357357

358-
select * from jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ == "1")');
358+
select * from jsonpath_query(jsonb '[1,"1",2,"2",null]', '$[*] ? (@ == "1")');
359359
jsonpath_query
360360
----------------
361361
"1"
362362
(1 row)
363363

364-
select * from jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ == $value)', '{"value" : "1"}');
364+
select * from jsonpath_query(jsonb '[1,"1",2,"2",null]', '$[*] ? (@ == $value)', '{"value" : "1"}');
365365
jsonpath_query
366366
----------------
367367
"1"

src/test/regress/expected/jsonpath.out

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,54 +39,24 @@ select '$.a.*'::jsonpath;
3939
$."a".*
4040
(1 row)
4141

42-
select '$.*.[*]'::jsonpath;
43-
jsonpath
44-
----------
45-
$.*[*]
46-
(1 row)
47-
4842
select '$.*[*]'::jsonpath;
4943
jsonpath
5044
----------
5145
$.*[*]
5246
(1 row)
5347

54-
select '$.a.[*]'::jsonpath;
55-
jsonpath
56-
----------
57-
$."a"[*]
58-
(1 row)
59-
6048
select '$.a[*]'::jsonpath;
6149
jsonpath
6250
----------
6351
$."a"[*]
6452
(1 row)
6553

66-
select '$.a.[*][*]'::jsonpath;
67-
jsonpath
68-
-------------
69-
$."a"[*][*]
70-
(1 row)
71-
72-
select '$.a.[*].[*]'::jsonpath;
73-
jsonpath
74-
-------------
75-
$."a"[*][*]
76-
(1 row)
77-
7854
select '$.a[*][*]'::jsonpath;
7955
jsonpath
8056
-------------
8157
$."a"[*][*]
8258
(1 row)
8359

84-
select '$.a[*].[*]'::jsonpath;
85-
jsonpath
86-
-------------
87-
$."a"[*][*]
88-
(1 row)
89-
9060
select '$[*]'::jsonpath;
9161
jsonpath
9262
----------
@@ -297,12 +267,6 @@ select '$.g ? (@.zip == $zip)'::jsonpath;
297267
$."g"?(@."zip" == $"zip")
298268
(1 row)
299269

300-
select '$.a.[1,2, 3 to 16]'::jsonpath;
301-
jsonpath
302-
--------------------
303-
$."a"[1,2,3 to 16]
304-
(1 row)
305-
306270
select '$.a[1,2, 3 to 16]'::jsonpath;
307271
jsonpath
308272
--------------------

src/test/regress/sql/jsonb_jsonpath.sql

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ select jsonb '{"a": 1}' @? '$.*';
88
select jsonb '{"a": {"b": 1}}' @? 'lax $.**{1}';
99
select jsonb '{"a": {"b": 1}}' @? 'lax $.**{2}';
1010
select jsonb '{"a": {"b": 1}}' @? 'lax $.**{3}';
11-
select jsonb '[]' @? '$.[*]';
12-
select jsonb '[1]' @? '$.[*]';
13-
select jsonb '[1]' @? '$.[1]';
14-
select jsonb '[1]' @? 'strict $.[1]';
11+
select jsonb '[]' @? '$[*]';
12+
select jsonb '[1]' @? '$[*]';
13+
select jsonb '[1]' @? '$[1]';
14+
select jsonb '[1]' @? 'strict $[1]';
1515
select jsonb '[1]' @* 'strict $[1]';
16-
select jsonb '[1]' @? '$.[0]';
17-
select jsonb '[1]' @? '$.[0.3]';
18-
select jsonb '[1]' @? '$.[0.5]';
19-
select jsonb '[1]' @? '$.[0.9]';
20-
select jsonb '[1]' @? '$.[1.2]';
21-
select jsonb '[1]' @? 'strict $.[1.2]';
16+
select jsonb '[1]' @? '$[0]';
17+
select jsonb '[1]' @? '$[0.3]';
18+
select jsonb '[1]' @? '$[0.5]';
19+
select jsonb '[1]' @? '$[0.9]';
20+
select jsonb '[1]' @? '$[1.2]';
21+
select jsonb '[1]' @? 'strict $[1.2]';
2222
select jsonb '{"a": [1,2,3], "b": [3,4,5]}' @? '$ ? (@.a[*] > @.b[*])';
2323
select jsonb '{"a": [1,2,3], "b": [3,4,5]}' @? '$ ? (@.a[*] >= @.b[*])';
2424
select jsonb '{"a": [1,2,3], "b": [3,4,"5"]}' @? '$ ? (@.a[*] >= @.b[*])';
@@ -32,14 +32,14 @@ select jsonb '{"a": 12, "b": {"a": 13}}' @* '$.a';
3232
select jsonb '{"a": 12, "b": {"a": 13}}' @* '$.b';
3333
select jsonb '{"a": 12, "b": {"a": 13}}' @* '$.*';
3434
select jsonb '{"a": 12, "b": {"a": 13}}' @* 'lax $.*.a';
35-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[*].a';
36-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[*].*';
37-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[0].a';
38-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[1].a';
39-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[2].a';
40-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[0,1].a';
41-
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $.[0 to 10].a';
42-
select jsonb '[12, {"a": 13}, {"b": 14}, "ccc", true]' @* '$.[2.5 - 1 to @.size() - 2]';
35+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[*].a';
36+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[*].*';
37+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[0].a';
38+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[1].a';
39+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[2].a';
40+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[0,1].a';
41+
select jsonb '[12, {"a": 13}, {"b": 14}]' @* 'lax $[0 to 10].a';
42+
select jsonb '[12, {"a": 13}, {"b": 14}, "ccc", true]' @* '$[2.5 - 1 to @.size() - 2]';
4343
select jsonb '1' @* 'lax $[0]';
4444
select jsonb '1' @* 'lax $[*]';
4545
select jsonb '[1]' @* 'lax $[0]';
@@ -58,11 +58,11 @@ select * from jsonpath_query(jsonb '{"a": 10}', '$ ? (.a < $value)');
5858
select * from jsonpath_query(jsonb '{"a": 10}', '$ ? (.a < $value)', '{"value" : 13}');
5959
select * from jsonpath_query(jsonb '{"a": 10}', '$ ? (.a < $value)', '{"value" : 8}');
6060
select * from jsonpath_query(jsonb '{"a": 10}', '$.a ? (@ < $value)', '{"value" : 13}');
61-
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[*] ? (@ < $value)', '{"value" : 13}');
62-
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[0,1] ? (@ < $value)', '{"value" : 13}');
63-
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$.[0 to 2] ? (@ < $value)', '{"value" : 15}');
64-
select * from jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ == "1")');
65-
select * from jsonpath_query(jsonb '[1,"1",2,"2",null]', '$.[*] ? (@ == $value)', '{"value" : "1"}');
61+
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$[*] ? (@ < $value)', '{"value" : 13}');
62+
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$[0,1] ? (@ < $value)', '{"value" : 13}');
63+
select * from jsonpath_query(jsonb '[10,11,12,13,14,15]', '$[0 to 2] ? (@ < $value)', '{"value" : 15}');
64+
select * from jsonpath_query(jsonb '[1,"1",2,"2",null]', '$[*] ? (@ == "1")');
65+
select * from jsonpath_query(jsonb '[1,"1",2,"2",null]', '$[*] ? (@ == $value)', '{"value" : "1"}');
6666
select * from jsonpath_query(jsonb '[1, "2", null]', '$[*] ? (@ != null)');
6767
select * from jsonpath_query(jsonb '[1, "2", null]', '$[*] ? (@ == null)');
6868

src/test/regress/sql/jsonpath.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ select 'lax $'::jsonpath;
77
select '$.a'::jsonpath;
88
select '$.a.v'::jsonpath;
99
select '$.a.*'::jsonpath;
10-
select '$.*.[*]'::jsonpath;
1110
select '$.*[*]'::jsonpath;
12-
select '$.a.[*]'::jsonpath;
1311
select '$.a[*]'::jsonpath;
14-
select '$.a.[*][*]'::jsonpath;
15-
select '$.a.[*].[*]'::jsonpath;
1612
select '$.a[*][*]'::jsonpath;
17-
select '$.a[*].[*]'::jsonpath;
1813
select '$[*]'::jsonpath;
1914
select '$[0]'::jsonpath;
2015
select '$[*][0]'::jsonpath;
@@ -52,7 +47,6 @@ select '$a'::jsonpath;
5247
select '$a.b'::jsonpath;
5348
select '$a[*]'::jsonpath;
5449
select '$.g ? (@.zip == $zip)'::jsonpath;
55-
select '$.a.[1,2, 3 to 16]'::jsonpath;
5650
select '$.a[1,2, 3 to 16]'::jsonpath;
5751
select '$.a[$a + 1, ($b[*]) to -(@[0] * 2)]'::jsonpath;
5852
select '$.a[$.a.size() - 3]'::jsonpath;

0 commit comments

Comments
 (0)