Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
--jsonpath io
|
|
|
|
select ''::jsonpath;
|
|
|
|
ERROR: invalid input syntax for jsonpath: ""
|
|
|
|
LINE 1: select ''::jsonpath;
|
|
|
|
^
|
|
|
|
select '$'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'strict $'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
strict $
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'lax $'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$."a"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.v'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------
|
|
|
|
$."a"."v"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.*'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$."a".*
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.*[*]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$.*[*]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a[*]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$."a"[*]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a[*][*]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------
|
|
|
|
$."a"[*][*]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$[*]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$[*]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$[0]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$[0]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$[*][0]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$[*][0]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$[*].a'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$[*]."a"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$[*][0].a.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$[*][0]."a"."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.**.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------
|
|
|
|
$."a".**."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.**{2}.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$."a".**{2}."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.**{2 to 2}.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$."a".**{2}."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.**{2 to 5}.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------
|
|
|
|
$."a".**{2 to 5}."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.**{0 to 5}.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------
|
|
|
|
$."a".**{0 to 5}."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.**{5 to last}.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------
|
|
|
|
$."a".**{5 to last}."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.**{last}.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------
|
|
|
|
$."a".**{last}."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a.**{last to 5}.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------
|
|
|
|
$."a".**{last to 5}."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$+1'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
($ + 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$-1'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
($ - 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$--+1'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
($ - -1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a/+-1'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------
|
|
|
|
($."a" / -1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1 * 2 + 4 % -3 != false'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------------------
|
|
|
|
(1 * 2 + 4 % -3 != false)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '"\b\f\r\n\t\v\"\''\\"'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------
|
|
|
|
"\b\f\r\n\t\u000b\"'\\"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '''\b\f\r\n\t\v\"\''\\'''::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------
|
|
|
|
"\b\f\r\n\t\u000b\"'\\"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '"\x50\u0067\u{53}\u{051}\u{00004C}"'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
"PgSQL"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '''\x50\u0067\u{53}\u{051}\u{00004C}'''::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
"PgSQL"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.foo\x50\u0067\u{53}\u{051}\u{00004C}\t\"bar'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------------
|
|
|
|
$."fooPgSQL\t\"bar"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? ($.a == 1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------
|
|
|
|
$."g"?($."a" == 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@ == 1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------
|
|
|
|
$."g"?(@ == 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@.a == 1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------
|
|
|
|
$."g"?(@."a" == 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@.a == 1 || @.a == 4)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------------------
|
|
|
|
$."g"?(@."a" == 1 || @."a" == 4)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@.a == 1 && @.a == 4)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------------------
|
|
|
|
$."g"?(@."a" == 1 && @."a" == 4)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@.a == 1 || @.a == 4 && @.b == 7)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------------------------------------
|
|
|
|
$."g"?(@."a" == 1 || @."a" == 4 && @."b" == 7)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@.a == 1 || !(@.a == 4) && @.b == 7)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------------------------------------------
|
|
|
|
$."g"?(@."a" == 1 || !(@."a" == 4) && @."b" == 7)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@.a == 1 || !(@.x >= 123 || @.a == 4) && @.b == 7)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------------------------------------------------
|
|
|
|
$."g"?(@."a" == 1 || !(@."x" >= 123 || @."a" == 4) && @."b" == 7)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@.x >= @[*]?(@.a > "abc"))'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------------------------------
|
|
|
|
$."g"?(@."x" >= @[*]?(@."a" > "abc"))
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? ((@.x >= 123 || @.a == 4) is unknown)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------------------------------
|
|
|
|
$."g"?((@."x" >= 123 || @."a" == 4) is unknown)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (exists (@.x))'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------------
|
|
|
|
$."g"?(exists (@."x"))
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (exists (@.x ? (@ == 14)))'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------------------
|
|
|
|
$."g"?(exists (@."x"?(@ == 14)))
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? ((@.x >= 123 || @.a == 4) && exists (@.x ? (@ == 14)))'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------------------------------------------------------
|
|
|
|
$."g"?((@."x" >= 123 || @."a" == 4) && exists (@."x"?(@ == 14)))
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (+@.x >= +-(+@.a + 2))'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------------------------
|
|
|
|
$."g"?(+@."x" >= +(-(+@."a" + 2)))
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$a'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$"a"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$a.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$"a"."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$a[*]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$"a"[*]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.g ? (@.zip == $zip)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------------------
|
|
|
|
$."g"?(@."zip" == $"zip")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a[1,2, 3 to 16]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------
|
|
|
|
$."a"[1,2,3 to 16]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a[$a + 1, ($b[*]) to -($[0] * 2)]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------------------------
|
|
|
|
$."a"[$"a" + 1,$"b"[*] to -($[0] * 2)]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.a[$.a.size() - 3]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------
|
|
|
|
$."a"[$."a".size() - 3]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'last'::jsonpath;
|
|
|
|
ERROR: LAST is allowed only in array subscripts
|
|
|
|
LINE 1: select 'last'::jsonpath;
|
|
|
|
^
|
|
|
|
select '"last"'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
"last"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.last'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$."last"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (last > 0)'::jsonpath;
|
|
|
|
ERROR: LAST is allowed only in array subscripts
|
|
|
|
LINE 1: select '$ ? (last > 0)'::jsonpath;
|
|
|
|
^
|
|
|
|
select '$[last]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$[last]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$[$[0] ? (last > 0)]'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------
|
|
|
|
$[$[0]?(last > 0)]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'null.type()'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------
|
|
|
|
null.type()
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1.type()'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1.type()
|
|
|
|
(1 row)
|
|
|
|
|
2019-03-25 13:43:56 +01:00
|
|
|
select '(1).type()'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1.type()
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1.2.type()'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------
|
|
|
|
1.2.type()
|
|
|
|
(1 row)
|
|
|
|
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '"aaa".type()'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------
|
|
|
|
"aaa".type()
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select 'true.type()'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------
|
|
|
|
true.type()
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.double().floor().ceiling().abs()'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------------------------
|
|
|
|
$.double().floor().ceiling().abs()
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$.keyvalue().key'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------
|
|
|
|
$.keyvalue()."key"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ starts with "abc")'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------
|
|
|
|
$?(@ starts with "abc")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ starts with $var)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------------
|
|
|
|
$?(@ starts with $"var")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ like_regex "(invalid pattern")'::jsonpath;
|
|
|
|
ERROR: invalid regular expression: parentheses () not balanced
|
|
|
|
LINE 1: select '$ ? (@ like_regex "(invalid pattern")'::jsonpath;
|
|
|
|
^
|
|
|
|
select '$ ? (@ like_regex "pattern")'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------------
|
|
|
|
$?(@ like_regex "pattern")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "")'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------------
|
|
|
|
$?(@ like_regex "pattern")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "i")'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------------------
|
|
|
|
$?(@ like_regex "pattern" flag "i")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "is")'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------------------------
|
|
|
|
$?(@ like_regex "pattern" flag "is")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "isim")'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------------------------
|
|
|
|
$?(@ like_regex "pattern" flag "im")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "xsms")'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
--------------------------------------
|
|
|
|
$?(@ like_regex "pattern" flag "sx")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: invalid input syntax for type jsonpath
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
LINE 1: select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath;
|
|
|
|
^
|
2019-04-23 16:43:09 +02:00
|
|
|
DETAIL: unrecognized flag character "a" in LIKE_REGEX predicate
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ < 1'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
($ < 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '($ < 1) || $.a.b <= $x'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------------------
|
|
|
|
($ < 1 || $."a"."b" <= $"x")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '@ + 1'::jsonpath;
|
|
|
|
ERROR: @ is not allowed in root expressions
|
|
|
|
LINE 1: select '@ + 1'::jsonpath;
|
|
|
|
^
|
|
|
|
select '($).a.b'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------
|
|
|
|
$."a"."b"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '($.a.b).c.d'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------
|
|
|
|
$."a"."b"."c"."d"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '($.a.b + -$.x.y).c.d'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------------------------
|
|
|
|
($."a"."b" + -$."x"."y")."c"."d"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '(-+$.a.b).c.d'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------
|
|
|
|
(-(+$."a"."b"))."c"."d"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1 + ($.a.b + 2).c.d'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------------
|
|
|
|
(1 + ($."a"."b" + 2)."c"."d")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1 + ($.a.b > 2).c.d'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------------
|
|
|
|
(1 + ($."a"."b" > 2)."c"."d")
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '($)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '(($))'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
$
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '((($ + 1)).a + ((2)).b ? ((((@ > 1)) || (exists(@.c)))))'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------------------------------------
|
|
|
|
(($ + 1)."a" + 2."b"?(@ > 1 || exists (@."c")))
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < 1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------
|
|
|
|
$?(@."a" < 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------
|
|
|
|
$?(@."a" < -1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------
|
|
|
|
$?(@."a" < 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < .1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < .1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < -.1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < -.1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < +.1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < +.1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < 0.1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < 0.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -0.1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < -0.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +0.1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < 0.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < 10.1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < 10.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -10.1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------
|
|
|
|
$?(@."a" < -10.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +10.1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < 10.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < 1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------
|
|
|
|
$?(@."a" < 10)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < -10)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------
|
|
|
|
$?(@."a" < 10)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < .1e1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < .1e1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < -.1e1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < -.1e1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < +.1e1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < +.1e1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < 0.1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------
|
|
|
|
$?(@."a" < 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -0.1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------
|
|
|
|
$?(@."a" < -1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +0.1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------
|
|
|
|
$?(@."a" < 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < 10.1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < 101)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -10.1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < -101)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +10.1e1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < 101)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < 1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < 0.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < -0.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < 0.1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < .1e-1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < .1e-1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < -.1e-1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < -.1e-1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < +.1e-1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < +.1e-1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < 0.1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < 0.01)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -0.1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------
|
|
|
|
$?(@."a" < -0.01)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +0.1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < 0.01)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < 10.1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < 1.01)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -10.1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------------
|
|
|
|
$?(@."a" < -1.01)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +10.1e-1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < 1.01)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < 1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------
|
|
|
|
$?(@."a" < 10)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < -10)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------
|
|
|
|
$?(@."a" < 10)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < .1e+1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < .1e+1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < -.1e+1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < -.1e+1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < +.1e+1)'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '$ ? (@.a < +.1e+1)'::jsonpath;
|
|
|
|
^
|
Partial implementation of SQL/JSON path language
SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database. The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them. This commit implements partial support JSON path language as
separate datatype called "jsonpath". The implementation is partial because
it's lacking datetime support and suppression of numeric errors. Missing
features will be added later by separate commits.
Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches. This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:
* jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
* jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
* jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).
This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly. These operators will have an index support
(implemented in subsequent patches).
Catversion bumped, to add new functions and operators.
Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova. The work
was inspired by Oleg Bartunov.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov
2019-03-16 10:15:37 +01:00
|
|
|
select '$ ? (@.a < 0.1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------
|
|
|
|
$?(@."a" < 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -0.1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------------
|
|
|
|
$?(@."a" < -1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +0.1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
---------------
|
|
|
|
$?(@."a" < 1)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < 10.1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < 101)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < -10.1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------------
|
|
|
|
$?(@."a" < -101)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '$ ? (@.a < +10.1e+1)'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-----------------
|
|
|
|
$?(@."a" < 101)
|
|
|
|
(1 row)
|
|
|
|
|
2019-03-25 13:43:56 +01:00
|
|
|
select '0'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '00'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected IDENT_P at end of jsonpath input
|
2019-04-01 17:09:09 +02:00
|
|
|
LINE 1: select '00'::jsonpath;
|
|
|
|
^
|
2019-03-25 13:43:56 +01:00
|
|
|
select '0.0'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0.0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '0.000'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0.000
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '0.000e1'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0.00
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '0.000e2'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0.0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '0.000e3'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '0.0010'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0.0010
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '0.0010e-1'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0.00010
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '0.0010e+1'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0.010
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '0.0010e+2'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
0.10
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1e'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: invalid floating point number at or near "1e" of jsonpath input
|
2019-03-25 13:43:56 +01:00
|
|
|
LINE 1: select '1e'::jsonpath;
|
|
|
|
^
|
|
|
|
select '1.e'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1."e"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1.2e'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: invalid floating point number at or near "1.2e" of jsonpath input
|
2019-03-25 13:43:56 +01:00
|
|
|
LINE 1: select '1.2e'::jsonpath;
|
|
|
|
^
|
|
|
|
select '1.2.e'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1.2."e"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '(1.2).e'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1.2."e"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1e3'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1000
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1.e3'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1."e3"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1.e3.e'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
------------
|
|
|
|
1."e3"."e"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1.e3.e4'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
-------------
|
|
|
|
1."e3"."e4"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1.2e3'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1200
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1.2.e3'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1.2."e3"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '(1.2).e3'::jsonpath;
|
|
|
|
jsonpath
|
|
|
|
----------
|
|
|
|
1.2."e3"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select '1..e'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-03-25 13:43:56 +01:00
|
|
|
LINE 1: select '1..e'::jsonpath;
|
|
|
|
^
|
|
|
|
select '1..e3'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
|
2019-03-25 13:43:56 +01:00
|
|
|
LINE 1: select '1..e3'::jsonpath;
|
|
|
|
^
|
|
|
|
select '(1.).e'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected ')' at or near ")" of jsonpath input
|
2019-03-25 13:43:56 +01:00
|
|
|
LINE 1: select '(1.).e'::jsonpath;
|
|
|
|
^
|
|
|
|
select '(1.).e3'::jsonpath;
|
2019-04-23 16:43:09 +02:00
|
|
|
ERROR: syntax error, unexpected ')' at or near ")" of jsonpath input
|
2019-03-25 13:43:56 +01:00
|
|
|
LINE 1: select '(1.).e3'::jsonpath;
|
|
|
|
^
|