@@ -1228,6 +1228,25 @@ select json '{}' @* '$.datetime()';
1228
1228
ERROR: Invalid argument for SQL/JSON datetime function
1229
1229
select json '""' @* '$.datetime()';
1230
1230
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
+
1231
1250
select json '"10-03-2017"' @* '$.datetime("dd-mm-yyyy")';
1232
1251
?column?
1233
1252
--------------
@@ -1688,6 +1707,12 @@ SELECT json '[{"a": 1}, {"a": 2}]' @* '$[*] ? (@.a > 10)';
1688
1707
----------
1689
1708
(0 rows)
1690
1709
1710
+ SELECT json '[{"a": 1}, {"a": 2}]' @* '[$[*].a]';
1711
+ ?column?
1712
+ ----------
1713
+ [1, 2]
1714
+ (1 row)
1715
+
1691
1716
SELECT json '[{"a": 1}, {"a": 2}]' @# '$[*].a';
1692
1717
?column?
1693
1718
----------
@@ -1706,6 +1731,12 @@ SELECT json '[{"a": 1}, {"a": 2}]' @# '$[*].a ? (@ > 10)';
1706
1731
1707
1732
(1 row)
1708
1733
1734
+ SELECT json '[{"a": 1}, {"a": 2}]' @# '[$[*].a]';
1735
+ ?column?
1736
+ ----------
1737
+ [1, 2]
1738
+ (1 row)
1739
+
1709
1740
SELECT json '[{"a": 1}, {"a": 2}]' @? '$[*] ? (@.a > 1)';
1710
1741
?column?
1711
1742
----------
@@ -1730,3 +1761,194 @@ SELECT json '[{"a": 1}, {"a": 2}]' @~ '$[*].a > 2';
1730
1761
f
1731
1762
(1 row)
1732
1763
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
+
0 commit comments