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

Commit 121839f

Browse files
author
Nikita Glukhov
committed
Add json tests for jsonpath extensions
1 parent e6aea20 commit 121839f

File tree

2 files changed

+269
-0
lines changed

2 files changed

+269
-0
lines changed

src/test/regress/expected/json_jsonpath.out

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,25 @@ select json '{}' @* '$.datetime()';
12281228
ERROR: Invalid argument for SQL/JSON datetime function
12291229
select json '""' @* '$.datetime()';
12301230
ERROR: Invalid argument for SQL/JSON datetime function
1231+
-- Standard extension: UNIX epoch to timestamptz
1232+
select json '0' @* '$.datetime()';
1233+
?column?
1234+
-----------------------------
1235+
"1970-01-01T00:00:00+00:00"
1236+
(1 row)
1237+
1238+
select json '0' @* '$.datetime().type()';
1239+
?column?
1240+
----------------------------
1241+
"timestamp with time zone"
1242+
(1 row)
1243+
1244+
select json '1490216035.5' @* '$.datetime()';
1245+
?column?
1246+
-------------------------------
1247+
"2017-03-22T20:53:55.5+00:00"
1248+
(1 row)
1249+
12311250
select json '"10-03-2017"' @* '$.datetime("dd-mm-yyyy")';
12321251
?column?
12331252
--------------
@@ -1688,6 +1707,12 @@ SELECT json '[{"a": 1}, {"a": 2}]' @* '$[*] ? (@.a > 10)';
16881707
----------
16891708
(0 rows)
16901709

1710+
SELECT json '[{"a": 1}, {"a": 2}]' @* '[$[*].a]';
1711+
?column?
1712+
----------
1713+
[1, 2]
1714+
(1 row)
1715+
16911716
SELECT json '[{"a": 1}, {"a": 2}]' @# '$[*].a';
16921717
?column?
16931718
----------
@@ -1706,6 +1731,12 @@ SELECT json '[{"a": 1}, {"a": 2}]' @# '$[*].a ? (@ > 10)';
17061731

17071732
(1 row)
17081733

1734+
SELECT json '[{"a": 1}, {"a": 2}]' @# '[$[*].a]';
1735+
?column?
1736+
----------
1737+
[1, 2]
1738+
(1 row)
1739+
17091740
SELECT json '[{"a": 1}, {"a": 2}]' @? '$[*] ? (@.a > 1)';
17101741
?column?
17111742
----------
@@ -1730,3 +1761,194 @@ SELECT json '[{"a": 1}, {"a": 2}]' @~ '$[*].a > 2';
17301761
f
17311762
(1 row)
17321763

1764+
-- extension: path sequences
1765+
select json '[1,2,3,4,5]' @* '10, 20, $[*], 30';
1766+
?column?
1767+
----------
1768+
10
1769+
20
1770+
1
1771+
2
1772+
3
1773+
4
1774+
5
1775+
30
1776+
(8 rows)
1777+
1778+
select json '[1,2,3,4,5]' @* 'lax 10, 20, $[*].a, 30';
1779+
?column?
1780+
----------
1781+
10
1782+
20
1783+
30
1784+
(3 rows)
1785+
1786+
select json '[1,2,3,4,5]' @* 'strict 10, 20, $[*].a, 30';
1787+
ERROR: SQL/JSON member not found
1788+
select json '[1,2,3,4,5]' @* '-(10, 20, $[1 to 3], 30)';
1789+
?column?
1790+
----------
1791+
-10
1792+
-20
1793+
-2
1794+
-3
1795+
-4
1796+
-30
1797+
(6 rows)
1798+
1799+
select json '[1,2,3,4,5]' @* 'lax (10, 20.5, $[1 to 3], "30").double()';
1800+
?column?
1801+
----------
1802+
10
1803+
20.5
1804+
2
1805+
3
1806+
4
1807+
30
1808+
(6 rows)
1809+
1810+
select json '[1,2,3,4,5]' @* '$[(0, $[*], 5) ? (@ == 3)]';
1811+
?column?
1812+
----------
1813+
4
1814+
(1 row)
1815+
1816+
select json '[1,2,3,4,5]' @* '$[(0, $[*], 3) ? (@ == 3)]';
1817+
ERROR: Invalid SQL/JSON subscript
1818+
-- extension: array constructors
1819+
select json '[1, 2, 3]' @* '[]';
1820+
?column?
1821+
----------
1822+
[]
1823+
(1 row)
1824+
1825+
select json '[1, 2, 3]' @* '[1, 2, $[*], 4, 5]';
1826+
?column?
1827+
-----------------------
1828+
[1, 2, 1, 2, 3, 4, 5]
1829+
(1 row)
1830+
1831+
select json '[1, 2, 3]' @* '[1, 2, $[*], 4, 5][*]';
1832+
?column?
1833+
----------
1834+
1
1835+
2
1836+
1
1837+
2
1838+
3
1839+
4
1840+
5
1841+
(7 rows)
1842+
1843+
select json '[1, 2, 3]' @* '[(1, (2, $[*])), (4, 5)]';
1844+
?column?
1845+
-----------------------
1846+
[1, 2, 1, 2, 3, 4, 5]
1847+
(1 row)
1848+
1849+
select json '[1, 2, 3]' @* '[[1, 2], [$[*], 4], 5, [(1,2)?(@ > 5)]]';
1850+
?column?
1851+
-------------------------------
1852+
[[1, 2], [1, 2, 3, 4], 5, []]
1853+
(1 row)
1854+
1855+
select json '[1, 2, 3]' @* 'strict [1, 2, $[*].a, 4, 5]';
1856+
ERROR: SQL/JSON member not found
1857+
select json '[[1, 2], [3, 4, 5], [], [6, 7]]' @* '[$[*][*] ? (@ > 3)]';
1858+
?column?
1859+
--------------
1860+
[4, 5, 6, 7]
1861+
(1 row)
1862+
1863+
-- extension: object constructors
1864+
select json '[1, 2, 3]' @* '{}';
1865+
?column?
1866+
----------
1867+
{}
1868+
(1 row)
1869+
1870+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}';
1871+
?column?
1872+
--------------------------------
1873+
{"a": 5, "b": [1, 2, 3, 4, 5]}
1874+
(1 row)
1875+
1876+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}.*';
1877+
?column?
1878+
-----------------
1879+
5
1880+
[1, 2, 3, 4, 5]
1881+
(2 rows)
1882+
1883+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}[*]';
1884+
?column?
1885+
--------------------------------
1886+
{"a": 5, "b": [1, 2, 3, 4, 5]}
1887+
(1 row)
1888+
1889+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": ($[*], 4, 5)}';
1890+
ERROR: Singleton SQL/JSON item required
1891+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": {x: $, y: $[1] > 2, z: "foo"}}';
1892+
?column?
1893+
---------------------------------------------------------
1894+
{"a": 5, "b": {"x": [1, 2, 3], "y": false, "z": "foo"}}
1895+
(1 row)
1896+
1897+
-- extension: object subscripting
1898+
select json '{"a": 1}' @? '$["a"]';
1899+
?column?
1900+
----------
1901+
t
1902+
(1 row)
1903+
1904+
select json '{"a": 1}' @? '$["b"]';
1905+
?column?
1906+
----------
1907+
f
1908+
(1 row)
1909+
1910+
select json '{"a": 1}' @? 'strict $["b"]';
1911+
?column?
1912+
----------
1913+
1914+
(1 row)
1915+
1916+
select json '{"a": 1}' @? '$["b", "a"]';
1917+
?column?
1918+
----------
1919+
t
1920+
(1 row)
1921+
1922+
select json '{"a": 1}' @* '$["a"]';
1923+
?column?
1924+
----------
1925+
1
1926+
(1 row)
1927+
1928+
select json '{"a": 1}' @* 'strict $["b"]';
1929+
ERROR: SQL/JSON member not found
1930+
select json '{"a": 1}' @* 'lax $["b"]';
1931+
?column?
1932+
----------
1933+
(0 rows)
1934+
1935+
select json '{"a": 1, "b": 2}' @* 'lax $["b", "c", "b", "a", 0 to 3]';
1936+
?column?
1937+
------------------
1938+
2
1939+
2
1940+
1
1941+
{"a": 1, "b": 2}
1942+
(4 rows)
1943+
1944+
select json 'null' @* '{"a": 1}["a"]';
1945+
?column?
1946+
----------
1947+
1
1948+
(1 row)
1949+
1950+
select json 'null' @* '{"a": 1}["b"]';
1951+
?column?
1952+
----------
1953+
(0 rows)
1954+

src/test/regress/sql/json_jsonpath.sql

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ select json '[]' @* 'strict $.datetime()';
255255
select json '{}' @* '$.datetime()';
256256
select json '""' @* '$.datetime()';
257257

258+
-- Standard extension: UNIX epoch to timestamptz
259+
select json '0' @* '$.datetime()';
260+
select json '0' @* '$.datetime().type()';
261+
select json '1490216035.5' @* '$.datetime()';
262+
258263
select json '"10-03-2017"' @* '$.datetime("dd-mm-yyyy")';
259264
select json '"10-03-2017"' @* '$.datetime("dd-mm-yyyy").type()';
260265
select json '"10-03-2017 12:34"' @* '$.datetime("dd-mm-yyyy")';
@@ -367,13 +372,55 @@ set time zone default;
367372

368373
SELECT json '[{"a": 1}, {"a": 2}]' @* '$[*]';
369374
SELECT json '[{"a": 1}, {"a": 2}]' @* '$[*] ? (@.a > 10)';
375+
SELECT json '[{"a": 1}, {"a": 2}]' @* '[$[*].a]';
370376

371377
SELECT json '[{"a": 1}, {"a": 2}]' @# '$[*].a';
372378
SELECT json '[{"a": 1}, {"a": 2}]' @# '$[*].a ? (@ == 1)';
373379
SELECT json '[{"a": 1}, {"a": 2}]' @# '$[*].a ? (@ > 10)';
380+
SELECT json '[{"a": 1}, {"a": 2}]' @# '[$[*].a]';
374381

375382
SELECT json '[{"a": 1}, {"a": 2}]' @? '$[*] ? (@.a > 1)';
376383
SELECT json '[{"a": 1}, {"a": 2}]' @? '$[*].a ? (@ > 2)';
377384

378385
SELECT json '[{"a": 1}, {"a": 2}]' @~ '$[*].a > 1';
379386
SELECT json '[{"a": 1}, {"a": 2}]' @~ '$[*].a > 2';
387+
388+
-- extension: path sequences
389+
select json '[1,2,3,4,5]' @* '10, 20, $[*], 30';
390+
select json '[1,2,3,4,5]' @* 'lax 10, 20, $[*].a, 30';
391+
select json '[1,2,3,4,5]' @* 'strict 10, 20, $[*].a, 30';
392+
select json '[1,2,3,4,5]' @* '-(10, 20, $[1 to 3], 30)';
393+
select json '[1,2,3,4,5]' @* 'lax (10, 20.5, $[1 to 3], "30").double()';
394+
select json '[1,2,3,4,5]' @* '$[(0, $[*], 5) ? (@ == 3)]';
395+
select json '[1,2,3,4,5]' @* '$[(0, $[*], 3) ? (@ == 3)]';
396+
397+
-- extension: array constructors
398+
select json '[1, 2, 3]' @* '[]';
399+
select json '[1, 2, 3]' @* '[1, 2, $[*], 4, 5]';
400+
select json '[1, 2, 3]' @* '[1, 2, $[*], 4, 5][*]';
401+
select json '[1, 2, 3]' @* '[(1, (2, $[*])), (4, 5)]';
402+
select json '[1, 2, 3]' @* '[[1, 2], [$[*], 4], 5, [(1,2)?(@ > 5)]]';
403+
select json '[1, 2, 3]' @* 'strict [1, 2, $[*].a, 4, 5]';
404+
select json '[[1, 2], [3, 4, 5], [], [6, 7]]' @* '[$[*][*] ? (@ > 3)]';
405+
406+
-- extension: object constructors
407+
select json '[1, 2, 3]' @* '{}';
408+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}';
409+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}.*';
410+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": [$[*], 4, 5]}[*]';
411+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": ($[*], 4, 5)}';
412+
select json '[1, 2, 3]' @* '{a: 2 + 3, "b": {x: $, y: $[1] > 2, z: "foo"}}';
413+
414+
-- extension: object subscripting
415+
select json '{"a": 1}' @? '$["a"]';
416+
select json '{"a": 1}' @? '$["b"]';
417+
select json '{"a": 1}' @? 'strict $["b"]';
418+
select json '{"a": 1}' @? '$["b", "a"]';
419+
420+
select json '{"a": 1}' @* '$["a"]';
421+
select json '{"a": 1}' @* 'strict $["b"]';
422+
select json '{"a": 1}' @* 'lax $["b"]';
423+
select json '{"a": 1, "b": 2}' @* 'lax $["b", "c", "b", "a", 0 to 3]';
424+
425+
select json 'null' @* '{"a": 1}["a"]';
426+
select json 'null' @* '{"a": 1}["b"]';

0 commit comments

Comments
 (0)