@@ -172,6 +172,32 @@ select json '[1]' @? 'strict $[1.2]';
172
172
173
173
(1 row)
174
174
175
+ select json_path_query('[1]', 'strict $[1.2]');
176
+ ERROR: jsonpath array subscript is out of bounds
177
+ select json_path_query('{}', 'strict $[0.3]');
178
+ ERROR: object subscript must be a string or number
179
+ select json '{}' @? 'lax $[0.3]';
180
+ ?column?
181
+ ----------
182
+ t
183
+ (1 row)
184
+
185
+ select json_path_query('{}', 'strict $[1.2]');
186
+ ERROR: object subscript must be a string or number
187
+ select json '{}' @? 'lax $[1.2]';
188
+ ?column?
189
+ ----------
190
+ f
191
+ (1 row)
192
+
193
+ select json_path_query('{}', 'strict $[-2 to 3]');
194
+ ERROR: jsonpath array accessor can only be applied to an array
195
+ select json '{}' @? 'lax $[-2 to 3]';
196
+ ?column?
197
+ ----------
198
+ t
199
+ (1 row)
200
+
175
201
select json '{"a": [1,2,3], "b": [3,4,5]}' @? '$ ? (@.a[*] > @.b[*])';
176
202
?column?
177
203
----------
@@ -244,7 +270,7 @@ select json_path_query('{}', 'lax $.a');
244
270
select json_path_query('{}', 'strict $.a');
245
271
ERROR: JSON object does not contain key "a"
246
272
select json_path_query('1', 'strict $[1]');
247
- ERROR: jsonpath array accessor can only be applied to an array
273
+ ERROR: jsonpath array accessor can only be applied to an array or object
248
274
select json_path_query('1', 'strict $[*]');
249
275
ERROR: jsonpath wildcard array accessor can only be applied to an array
250
276
select json_path_query('[]', 'strict $[1]');
@@ -339,6 +365,12 @@ select json_path_query('1', 'lax $[*]');
339
365
1
340
366
(1 row)
341
367
368
+ select json_path_query('{}', 'lax $[0]');
369
+ json_path_query
370
+ -----------------
371
+ {}
372
+ (1 row)
373
+
342
374
select json_path_query('[1]', 'lax $[0]');
343
375
json_path_query
344
376
-----------------
@@ -379,6 +411,12 @@ select json_path_query('[1]', '$[last]');
379
411
1
380
412
(1 row)
381
413
414
+ select json_path_query('{}', '$[last]');
415
+ json_path_query
416
+ -----------------
417
+ {}
418
+ (1 row)
419
+
382
420
select json_path_query('[1,2,3]', '$[last]');
383
421
json_path_query
384
422
-----------------
@@ -1438,20 +1476,18 @@ select json_path_query('[null, 1, "abc", "abd", "aBdC", "abdacb", "adc\nabc", "b
1438
1476
(2 rows)
1439
1477
1440
1478
select json_path_query('null', '$.datetime()');
1441
- ERROR: jsonpath item method .datetime() can only be applied to a string value
1479
+ ERROR: jsonpath item method .datetime() can only be applied to a string or number
1442
1480
select json_path_query('true', '$.datetime()');
1443
- ERROR: jsonpath item method .datetime() can only be applied to a string value
1444
- select json_path_query('1', '$.datetime()');
1445
- ERROR: jsonpath item method .datetime() can only be applied to a string value
1481
+ ERROR: jsonpath item method .datetime() can only be applied to a string or number
1446
1482
select json_path_query('[]', '$.datetime()');
1447
1483
json_path_query
1448
1484
-----------------
1449
1485
(0 rows)
1450
1486
1451
1487
select json_path_query('[]', 'strict $.datetime()');
1452
- ERROR: jsonpath item method .datetime() can only be applied to a string value
1488
+ ERROR: jsonpath item method .datetime() can only be applied to a string or number
1453
1489
select json_path_query('{}', '$.datetime()');
1454
- ERROR: jsonpath item method .datetime() can only be applied to a string value
1490
+ ERROR: jsonpath item method .datetime() can only be applied to a string or number
1455
1491
select json_path_query('""', '$.datetime()');
1456
1492
ERROR: unrecognized datetime format
1457
1493
HINT: use datetime template argument for explicit format specification
@@ -1488,6 +1524,25 @@ ERROR: timezone argument of jsonpath item method .datetime() is out of integer
1488
1524
select json_path_query('"aaaa"', '$.datetime("HH24")');
1489
1525
ERROR: invalid value "aa" for "HH24"
1490
1526
DETAIL: Value must be an integer.
1527
+ -- Standard extension: UNIX epoch to timestamptz
1528
+ select json_path_query('0', '$.datetime()');
1529
+ json_path_query
1530
+ -----------------------------
1531
+ "1970-01-01T00:00:00+00:00"
1532
+ (1 row)
1533
+
1534
+ select json_path_query('0', '$.datetime().type()');
1535
+ json_path_query
1536
+ ----------------------------
1537
+ "timestamp with time zone"
1538
+ (1 row)
1539
+
1540
+ select json_path_query('1490216035.5', '$.datetime()');
1541
+ json_path_query
1542
+ -------------------------------
1543
+ "2017-03-22T20:53:55.5+00:00"
1544
+ (1 row)
1545
+
1491
1546
select json '"10-03-2017"' @? '$.datetime("dd-mm-yyyy")';
1492
1547
?column?
1493
1548
----------
@@ -1975,6 +2030,12 @@ SELECT json_path_query('[{"a": 1}, {"a": 2}]', '$[*] ? (@.a > 10)');
1975
2030
-----------------
1976
2031
(0 rows)
1977
2032
2033
+ SELECT json_path_query('[{"a": 1}, {"a": 2}]', '[$[*].a]');
2034
+ json_path_query
2035
+ -----------------
2036
+ [1, 2]
2037
+ (1 row)
2038
+
1978
2039
SELECT json_path_query_array('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a');
1979
2040
ERROR: JSON object does not contain key "a"
1980
2041
SELECT json_path_query_array('[{"a": 1}, {"a": 2}]', '$[*].a');
@@ -2007,6 +2068,12 @@ SELECT json_path_query_array('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].a
2007
2068
[]
2008
2069
(1 row)
2009
2070
2071
+ SELECT json_path_query_array('[{"a": 1}, {"a": 2}]', '[$[*].a]');
2072
+ json_path_query_array
2073
+ -----------------------
2074
+ [[1, 2]]
2075
+ (1 row)
2076
+
2010
2077
SELECT json_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a');
2011
2078
ERROR: JSON object does not contain key "a"
2012
2079
SELECT json_path_query_first('[{"a": 1}, {"a": 2}]', '$[*].a');
@@ -2075,3 +2142,194 @@ SELECT json '[{"a": 1}, {"a": 2}]' @@ '$[*].a > 2';
2075
2142
f
2076
2143
(1 row)
2077
2144
2145
+ -- extension: path sequences
2146
+ select json_path_query('[1,2,3,4,5]', '10, 20, $[*], 30');
2147
+ json_path_query
2148
+ -----------------
2149
+ 10
2150
+ 20
2151
+ 1
2152
+ 2
2153
+ 3
2154
+ 4
2155
+ 5
2156
+ 30
2157
+ (8 rows)
2158
+
2159
+ select json_path_query('[1,2,3,4,5]', 'lax 10, 20, $[*].a, 30');
2160
+ json_path_query
2161
+ -----------------
2162
+ 10
2163
+ 20
2164
+ 30
2165
+ (3 rows)
2166
+
2167
+ select json_path_query('[1,2,3,4,5]', 'strict 10, 20, $[*].a, 30');
2168
+ ERROR: jsonpath member accessor can only be applied to an object
2169
+ select json_path_query('[1,2,3,4,5]', '-(10, 20, $[1 to 3], 30)');
2170
+ json_path_query
2171
+ -----------------
2172
+ -10
2173
+ -20
2174
+ -2
2175
+ -3
2176
+ -4
2177
+ -30
2178
+ (6 rows)
2179
+
2180
+ select json_path_query('[1,2,3,4,5]', 'lax (10, 20.5, $[1 to 3], "30").double()');
2181
+ json_path_query
2182
+ -----------------
2183
+ 10
2184
+ 20.5
2185
+ 2
2186
+ 3
2187
+ 4
2188
+ 30
2189
+ (6 rows)
2190
+
2191
+ select json_path_query('[1,2,3,4,5]', '$[(0, $[*], 5) ? (@ == 3)]');
2192
+ json_path_query
2193
+ -----------------
2194
+ 4
2195
+ (1 row)
2196
+
2197
+ select json_path_query('[1,2,3,4,5]', '$[(0, $[*], 3) ? (@ == 3)]');
2198
+ ERROR: jsonpath array subscript is not a single numeric value
2199
+ -- extension: array constructors
2200
+ select json_path_query('[1, 2, 3]', '[]');
2201
+ json_path_query
2202
+ -----------------
2203
+ []
2204
+ (1 row)
2205
+
2206
+ select json_path_query('[1, 2, 3]', '[1, 2, $[*], 4, 5]');
2207
+ json_path_query
2208
+ -----------------------
2209
+ [1, 2, 1, 2, 3, 4, 5]
2210
+ (1 row)
2211
+
2212
+ select json_path_query('[1, 2, 3]', '[1, 2, $[*], 4, 5][*]');
2213
+ json_path_query
2214
+ -----------------
2215
+ 1
2216
+ 2
2217
+ 1
2218
+ 2
2219
+ 3
2220
+ 4
2221
+ 5
2222
+ (7 rows)
2223
+
2224
+ select json_path_query('[1, 2, 3]', '[(1, (2, $[*])), (4, 5)]');
2225
+ json_path_query
2226
+ -----------------------
2227
+ [1, 2, 1, 2, 3, 4, 5]
2228
+ (1 row)
2229
+
2230
+ select json_path_query('[1, 2, 3]', '[[1, 2], [$[*], 4], 5, [(1,2)?(@ > 5)]]');
2231
+ json_path_query
2232
+ -------------------------------
2233
+ [[1, 2], [1, 2, 3, 4], 5, []]
2234
+ (1 row)
2235
+
2236
+ select json_path_query('[1, 2, 3]', 'strict [1, 2, $[*].a, 4, 5]');
2237
+ ERROR: jsonpath member accessor can only be applied to an object
2238
+ select json_path_query('[[1, 2], [3, 4, 5], [], [6, 7]]', '[$[*][*] ? (@ > 3)]');
2239
+ json_path_query
2240
+ -----------------
2241
+ [4, 5, 6, 7]
2242
+ (1 row)
2243
+
2244
+ -- extension: object constructors
2245
+ select json_path_query('[1, 2, 3]', '{}');
2246
+ json_path_query
2247
+ -----------------
2248
+ {}
2249
+ (1 row)
2250
+
2251
+ select json_path_query('[1, 2, 3]', '{a: 2 + 3, "b": [$[*], 4, 5]}');
2252
+ json_path_query
2253
+ --------------------------------
2254
+ {"a": 5, "b": [1, 2, 3, 4, 5]}
2255
+ (1 row)
2256
+
2257
+ select json_path_query('[1, 2, 3]', '{a: 2 + 3, "b": [$[*], 4, 5]}.*');
2258
+ json_path_query
2259
+ -----------------
2260
+ 5
2261
+ [1, 2, 3, 4, 5]
2262
+ (2 rows)
2263
+
2264
+ select json_path_query('[1, 2, 3]', '{a: 2 + 3, "b": [$[*], 4, 5]}[*]');
2265
+ json_path_query
2266
+ --------------------------------
2267
+ {"a": 5, "b": [1, 2, 3, 4, 5]}
2268
+ (1 row)
2269
+
2270
+ select json_path_query('[1, 2, 3]', '{a: 2 + 3, "b": ($[*], 4, 5)}');
2271
+ ERROR: value in jsonpath object constructor must be a singleton
2272
+ select json_path_query('[1, 2, 3]', '{a: 2 + 3, "b": {x: $, y: $[1] > 2, z: "foo"}}');
2273
+ json_path_query
2274
+ ---------------------------------------------------------
2275
+ {"a": 5, "b": {"x": [1, 2, 3], "y": false, "z": "foo"}}
2276
+ (1 row)
2277
+
2278
+ -- extension: object subscripting
2279
+ select json '{"a": 1}' @? '$["a"]';
2280
+ ?column?
2281
+ ----------
2282
+ t
2283
+ (1 row)
2284
+
2285
+ select json '{"a": 1}' @? '$["b"]';
2286
+ ?column?
2287
+ ----------
2288
+ f
2289
+ (1 row)
2290
+
2291
+ select json '{"a": 1}' @? 'strict $["b"]';
2292
+ ?column?
2293
+ ----------
2294
+
2295
+ (1 row)
2296
+
2297
+ select json '{"a": 1}' @? '$["b", "a"]';
2298
+ ?column?
2299
+ ----------
2300
+ t
2301
+ (1 row)
2302
+
2303
+ select json_path_query('{"a": 1}', '$["a"]');
2304
+ json_path_query
2305
+ -----------------
2306
+ 1
2307
+ (1 row)
2308
+
2309
+ select json_path_query('{"a": 1}', 'strict $["b"]');
2310
+ ERROR: JSON object does not contain the specified key
2311
+ select json_path_query('{"a": 1}', 'lax $["b"]');
2312
+ json_path_query
2313
+ -----------------
2314
+ (0 rows)
2315
+
2316
+ select json_path_query('{"a": 1, "b": 2}', 'lax $["b", "c", "b", "a", 0 to 3]');
2317
+ json_path_query
2318
+ ------------------
2319
+ 2
2320
+ 2
2321
+ 1
2322
+ {"a": 1, "b": 2}
2323
+ (4 rows)
2324
+
2325
+ select json_path_query('null', '{"a": 1}["a"]');
2326
+ json_path_query
2327
+ -----------------
2328
+ 1
2329
+ (1 row)
2330
+
2331
+ select json_path_query('null', '{"a": 1}["b"]');
2332
+ json_path_query
2333
+ -----------------
2334
+ (0 rows)
2335
+
0 commit comments