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;
|
|
|
|
select '$'::jsonpath;
|
|
|
|
select 'strict $'::jsonpath;
|
|
|
|
select 'lax $'::jsonpath;
|
|
|
|
select '$.a'::jsonpath;
|
|
|
|
select '$.a.v'::jsonpath;
|
|
|
|
select '$.a.*'::jsonpath;
|
|
|
|
select '$.*[*]'::jsonpath;
|
|
|
|
select '$.a[*]'::jsonpath;
|
|
|
|
select '$.a[*][*]'::jsonpath;
|
|
|
|
select '$[*]'::jsonpath;
|
|
|
|
select '$[0]'::jsonpath;
|
|
|
|
select '$[*][0]'::jsonpath;
|
|
|
|
select '$[*].a'::jsonpath;
|
|
|
|
select '$[*][0].a.b'::jsonpath;
|
|
|
|
select '$.a.**.b'::jsonpath;
|
|
|
|
select '$.a.**{2}.b'::jsonpath;
|
|
|
|
select '$.a.**{2 to 2}.b'::jsonpath;
|
|
|
|
select '$.a.**{2 to 5}.b'::jsonpath;
|
|
|
|
select '$.a.**{0 to 5}.b'::jsonpath;
|
|
|
|
select '$.a.**{5 to last}.b'::jsonpath;
|
|
|
|
select '$.a.**{last}.b'::jsonpath;
|
|
|
|
select '$.a.**{last to 5}.b'::jsonpath;
|
|
|
|
select '$+1'::jsonpath;
|
|
|
|
select '$-1'::jsonpath;
|
|
|
|
select '$--+1'::jsonpath;
|
|
|
|
select '$.a/+-1'::jsonpath;
|
|
|
|
select '1 * 2 + 4 % -3 != false'::jsonpath;
|
|
|
|
|
|
|
|
select '"\b\f\r\n\t\v\"\''\\"'::jsonpath;
|
|
|
|
select '"\x50\u0067\u{53}\u{051}\u{00004C}"'::jsonpath;
|
|
|
|
select '$.foo\x50\u0067\u{53}\u{051}\u{00004C}\t\"bar'::jsonpath;
|
2019-09-20 20:22:58 +02:00
|
|
|
select '"\z"'::jsonpath; -- unrecognized escape is just the literal char
|
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 '$.g ? ($.a == 1)'::jsonpath;
|
|
|
|
select '$.g ? (@ == 1)'::jsonpath;
|
|
|
|
select '$.g ? (@.a == 1)'::jsonpath;
|
|
|
|
select '$.g ? (@.a == 1 || @.a == 4)'::jsonpath;
|
|
|
|
select '$.g ? (@.a == 1 && @.a == 4)'::jsonpath;
|
|
|
|
select '$.g ? (@.a == 1 || @.a == 4 && @.b == 7)'::jsonpath;
|
|
|
|
select '$.g ? (@.a == 1 || !(@.a == 4) && @.b == 7)'::jsonpath;
|
|
|
|
select '$.g ? (@.a == 1 || !(@.x >= 123 || @.a == 4) && @.b == 7)'::jsonpath;
|
|
|
|
select '$.g ? (@.x >= @[*]?(@.a > "abc"))'::jsonpath;
|
|
|
|
select '$.g ? ((@.x >= 123 || @.a == 4) is unknown)'::jsonpath;
|
|
|
|
select '$.g ? (exists (@.x))'::jsonpath;
|
|
|
|
select '$.g ? (exists (@.x ? (@ == 14)))'::jsonpath;
|
|
|
|
select '$.g ? ((@.x >= 123 || @.a == 4) && exists (@.x ? (@ == 14)))'::jsonpath;
|
|
|
|
select '$.g ? (+@.x >= +-(+@.a + 2))'::jsonpath;
|
|
|
|
|
|
|
|
select '$a'::jsonpath;
|
|
|
|
select '$a.b'::jsonpath;
|
|
|
|
select '$a[*]'::jsonpath;
|
|
|
|
select '$.g ? (@.zip == $zip)'::jsonpath;
|
|
|
|
select '$.a[1,2, 3 to 16]'::jsonpath;
|
|
|
|
select '$.a[$a + 1, ($b[*]) to -($[0] * 2)]'::jsonpath;
|
|
|
|
select '$.a[$.a.size() - 3]'::jsonpath;
|
|
|
|
select 'last'::jsonpath;
|
|
|
|
select '"last"'::jsonpath;
|
|
|
|
select '$.last'::jsonpath;
|
|
|
|
select '$ ? (last > 0)'::jsonpath;
|
|
|
|
select '$[last]'::jsonpath;
|
|
|
|
select '$[$[0] ? (last > 0)]'::jsonpath;
|
|
|
|
|
|
|
|
select 'null.type()'::jsonpath;
|
|
|
|
select '1.type()'::jsonpath;
|
2019-03-25 13:43:56 +01:00
|
|
|
select '(1).type()'::jsonpath;
|
|
|
|
select '1.2.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
|
|
|
select '"aaa".type()'::jsonpath;
|
|
|
|
select 'true.type()'::jsonpath;
|
|
|
|
select '$.double().floor().ceiling().abs()'::jsonpath;
|
|
|
|
select '$.keyvalue().key'::jsonpath;
|
Implement jsonpath .datetime() method
This commit implements jsonpath .datetime() method as it's specified in
SQL/JSON standard. There are no-argument and single-argument versions of
this method. No-argument version selects first of ISO datetime formats
matching input string. Single-argument version accepts template string as
its argument.
Additionally to .datetime() method itself this commit also implements
comparison ability of resulting date and time values. There is some difficulty
because exising jsonb_path_*() functions are immutable, while comparison of
timezoned and non-timezoned types involves current timezone. At first, current
timezone could be changes in session. Moreover, timezones themselves are not
immutable and could be updated. This is why we let existing immutable functions
throw errors on such non-immutable comparison. In the same time this commit
provides jsonb_path_*_tz() functions which are stable and support operations
involving timezones. As new functions are added to the system catalog,
catversion is bumped.
Support of .datetime() method was the only blocker prevents T832 from being
marked as supported. sql_features.txt is updated correspondingly.
Extracted from original patch by Nikita Glukhov, Teodor Sigaev, Oleg Bartunov.
Heavily revised by me. Comments were adjusted by Liudmila Mantrova.
Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Alexander Korotkov, Nikita Glukhov, Teodor Sigaev, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
2019-09-25 20:54:14 +02:00
|
|
|
select '$.datetime()'::jsonpath;
|
|
|
|
select '$.datetime("datetime template")'::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 '$ ? (@ starts with "abc")'::jsonpath;
|
|
|
|
select '$ ? (@ starts with $var)'::jsonpath;
|
|
|
|
|
|
|
|
select '$ ? (@ like_regex "(invalid pattern")'::jsonpath;
|
|
|
|
select '$ ? (@ like_regex "pattern")'::jsonpath;
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "")'::jsonpath;
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "i")'::jsonpath;
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "is")'::jsonpath;
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "isim")'::jsonpath;
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "xsms")'::jsonpath;
|
2019-06-19 21:40:58 +02:00
|
|
|
select '$ ? (@ like_regex "pattern" flag "q")'::jsonpath;
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "iq")'::jsonpath;
|
|
|
|
select '$ ? (@ like_regex "pattern" flag "smixq")'::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 '$ ? (@ like_regex "pattern" flag "a")'::jsonpath;
|
|
|
|
|
|
|
|
select '$ < 1'::jsonpath;
|
|
|
|
select '($ < 1) || $.a.b <= $x'::jsonpath;
|
|
|
|
select '@ + 1'::jsonpath;
|
|
|
|
|
|
|
|
select '($).a.b'::jsonpath;
|
|
|
|
select '($.a.b).c.d'::jsonpath;
|
|
|
|
select '($.a.b + -$.x.y).c.d'::jsonpath;
|
|
|
|
select '(-+$.a.b).c.d'::jsonpath;
|
|
|
|
select '1 + ($.a.b + 2).c.d'::jsonpath;
|
|
|
|
select '1 + ($.a.b > 2).c.d'::jsonpath;
|
|
|
|
select '($)'::jsonpath;
|
|
|
|
select '(($))'::jsonpath;
|
|
|
|
select '((($ + 1)).a + ((2)).b ? ((((@ > 1)) || (exists(@.c)))))'::jsonpath;
|
|
|
|
|
|
|
|
select '$ ? (@.a < 1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < .1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -.1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +.1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 0.1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -0.1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +0.1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 10.1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -10.1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +10.1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < .1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -.1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +.1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 0.1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -0.1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +0.1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 10.1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -10.1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +10.1e1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < .1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -.1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +.1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 0.1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -0.1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +0.1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 10.1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -10.1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +10.1e-1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < .1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -.1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +.1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 0.1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -0.1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +0.1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < 10.1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < -10.1e+1)'::jsonpath;
|
|
|
|
select '$ ? (@.a < +10.1e+1)'::jsonpath;
|
2019-03-25 13:43:56 +01:00
|
|
|
|
|
|
|
select '0'::jsonpath;
|
|
|
|
select '00'::jsonpath;
|
|
|
|
select '0.0'::jsonpath;
|
|
|
|
select '0.000'::jsonpath;
|
|
|
|
select '0.000e1'::jsonpath;
|
|
|
|
select '0.000e2'::jsonpath;
|
|
|
|
select '0.000e3'::jsonpath;
|
|
|
|
select '0.0010'::jsonpath;
|
|
|
|
select '0.0010e-1'::jsonpath;
|
|
|
|
select '0.0010e+1'::jsonpath;
|
|
|
|
select '0.0010e+2'::jsonpath;
|
|
|
|
select '1e'::jsonpath;
|
|
|
|
select '1.e'::jsonpath;
|
|
|
|
select '1.2e'::jsonpath;
|
|
|
|
select '1.2.e'::jsonpath;
|
|
|
|
select '(1.2).e'::jsonpath;
|
|
|
|
select '1e3'::jsonpath;
|
|
|
|
select '1.e3'::jsonpath;
|
|
|
|
select '1.e3.e'::jsonpath;
|
|
|
|
select '1.e3.e4'::jsonpath;
|
|
|
|
select '1.2e3'::jsonpath;
|
|
|
|
select '1.2.e3'::jsonpath;
|
|
|
|
select '(1.2).e3'::jsonpath;
|
|
|
|
select '1..e'::jsonpath;
|
|
|
|
select '1..e3'::jsonpath;
|
|
|
|
select '(1.).e'::jsonpath;
|
|
|
|
select '(1.).e3'::jsonpath;
|