postgresql/src/test/regress/expected/jsonpath.out

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1297 lines
26 KiB
Plaintext
Raw Normal View History

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 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 ''::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 '"\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 '"\z"'::jsonpath; -- unrecognized escape is just the literal char
jsonpath
----------
"z"
(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 '$.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;
ERROR: trailing junk after numeric literal at or near "1.t" of jsonpath input
LINE 1: select '1.type()'::jsonpath;
^
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)
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;
jsonpath
--------------
$.datetime()
(1 row)
select '$.datetime("datetime template")'::jsonpath;
jsonpath
---------------------------------
$.datetime("datetime template")
(1 row)
Implement various jsonpath methods This commit implements ithe jsonpath .bigint(), .boolean(), .date(), .decimal([precision [, scale]]), .integer(), .number(), .string(), .time(), .time_tz(), .timestamp(), and .timestamp_tz() methods. .bigint() converts the given JSON string or a numeric value to the bigint type representation. .boolean() converts the given JSON string, numeric, or boolean value to the boolean type representation. In the numeric case, only integers are allowed. We use the parse_bool() backend function to convert a string to a bool. .decimal([precision [, scale]]) converts the given JSON string or a numeric value to the numeric type representation. If precision and scale are provided for .decimal(), then it is converted to the equivalent numeric typmod and applied to the numeric number. .integer() and .number() convert the given JSON string or a numeric value to the int4 and numeric type representation. .string() uses the datatype's output function to convert numeric and various date/time types to the string representation. The JSON string representing a valid date/time is converted to the specific date or time type representation using jsonpath .date(), .time(), .time_tz(), .timestamp(), .timestamp_tz() methods. The changes use the infrastructure of the .datetime() method and perform the datatype conversion as appropriate. Unlike the .datetime() method, none of these methods accept a format template and use ISO DateTime format instead. However, except for .date(), the date/time related methods take an optional precision to adjust the fractional seconds. Jeevan Chalke, reviewed by Peter Eisentraut and Andrew Dunstan.
2024-01-25 16:15:43 +01:00
select '$.bigint().integer().number().decimal()'::jsonpath;
jsonpath
-----------------------------------------
$.bigint().integer().number().decimal()
(1 row)
select '$.boolean()'::jsonpath;
jsonpath
-------------
$.boolean()
(1 row)
select '$.date()'::jsonpath;
jsonpath
----------
$.date()
(1 row)
select '$.decimal(4,2)'::jsonpath;
jsonpath
----------------
$.decimal(4,2)
(1 row)
select '$.string()'::jsonpath;
jsonpath
------------
$.string()
(1 row)
select '$.time()'::jsonpath;
jsonpath
----------
$.time()
(1 row)
select '$.time(6)'::jsonpath;
jsonpath
-----------
$.time(6)
(1 row)
select '$.time_tz()'::jsonpath;
jsonpath
-------------
$.time_tz()
(1 row)
select '$.time_tz(4)'::jsonpath;
jsonpath
--------------
$.time_tz(4)
(1 row)
select '$.timestamp()'::jsonpath;
jsonpath
---------------
$.timestamp()
(1 row)
select '$.timestamp(2)'::jsonpath;
jsonpath
----------------
$.timestamp(2)
(1 row)
select '$.timestamp_tz()'::jsonpath;
jsonpath
------------------
$.timestamp_tz()
(1 row)
select '$.timestamp_tz(0)'::jsonpath;
jsonpath
-------------------
$.timestamp_tz(0)
(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 '$ ? (@ 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;
Fix bogus handling of XQuery regex option flags. The SQL spec defers to XQuery to define what the option flags are for LIKE_REGEX patterns. XQuery says that: * 's' allows the dot character to match newlines, which by default it will not; * 'm' allows ^ and $ to match at newlines, not only at the start/end of the whole string. Thus, these are *not* inverses as they are for the similarly-named POSIX options, and neither one corresponds to the POSIX 'n' option. Fortunately, Spencer's library does expose these two behaviors as separately twiddlable flags, so we just have to fix the mapping from JSP flag bits to REG flag bits. I also chose to rename the symbol for 's' to DOTALL, to make it clearer that it's not the inverse of MLINE. Also, XQuery says that if the 'q' flag "is used together with the m, s, or x flag, that flag has no effect". I read this as saying that 'q' overrides the other flags; whoever wrote our code seems to have read it backwards. Lastly, while XQuery's 'x' flag is related to what Spencer's code does for REG_EXPANDED, it's not the same or a subset. It seems best to treat XQuery's 'x' as unimplemented for now. Maybe later we can expand our regex code to offer 'x'-style parsing as a separate option. While at it, refactor the jsonpath code so that (a) there's only one copy of the flag transformation logic not two, and (b) the processing of flags is independent of the order in which the flags are written. We need some documentation updates to go with this, but I'll tackle that separately. Back-patch to v12 where this code originated. Discussion: https://postgr.es/m/CAPpHfdvDci4iqNF9fhRkTqhe-5_8HmzeLt56drH%2B_Rv2rNRqfg@mail.gmail.com Reference: https://www.w3.org/TR/2017/REC-xpath-functions-31-20170321/#flags
2019-09-17 21:39:51 +02:00
jsonpath
---------------------------------------
$?(@ like_regex "pattern" flag "ism")
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
(1 row)
select '$ ? (@ like_regex "pattern" flag "xsms")'::jsonpath;
Fix bogus handling of XQuery regex option flags. The SQL spec defers to XQuery to define what the option flags are for LIKE_REGEX patterns. XQuery says that: * 's' allows the dot character to match newlines, which by default it will not; * 'm' allows ^ and $ to match at newlines, not only at the start/end of the whole string. Thus, these are *not* inverses as they are for the similarly-named POSIX options, and neither one corresponds to the POSIX 'n' option. Fortunately, Spencer's library does expose these two behaviors as separately twiddlable flags, so we just have to fix the mapping from JSP flag bits to REG flag bits. I also chose to rename the symbol for 's' to DOTALL, to make it clearer that it's not the inverse of MLINE. Also, XQuery says that if the 'q' flag "is used together with the m, s, or x flag, that flag has no effect". I read this as saying that 'q' overrides the other flags; whoever wrote our code seems to have read it backwards. Lastly, while XQuery's 'x' flag is related to what Spencer's code does for REG_EXPANDED, it's not the same or a subset. It seems best to treat XQuery's 'x' as unimplemented for now. Maybe later we can expand our regex code to offer 'x'-style parsing as a separate option. While at it, refactor the jsonpath code so that (a) there's only one copy of the flag transformation logic not two, and (b) the processing of flags is independent of the order in which the flags are written. We need some documentation updates to go with this, but I'll tackle that separately. Back-patch to v12 where this code originated. Discussion: https://postgr.es/m/CAPpHfdvDci4iqNF9fhRkTqhe-5_8HmzeLt56drH%2B_Rv2rNRqfg@mail.gmail.com Reference: https://www.w3.org/TR/2017/REC-xpath-functions-31-20170321/#flags
2019-09-17 21:39:51 +02:00
ERROR: XQuery "x" flag (expanded regular expressions) is not implemented
LINE 1: select '$ ? (@ like_regex "pattern" flag "xsms")'::jsonpath;
^
select '$ ? (@ like_regex "pattern" flag "q")'::jsonpath;
jsonpath
-------------------------------------
$?(@ like_regex "pattern" flag "q")
(1 row)
select '$ ? (@ like_regex "pattern" flag "iq")'::jsonpath;
jsonpath
--------------------------------------
$?(@ like_regex "pattern" flag "iq")
(1 row)
select '$ ? (@ like_regex "pattern" flag "smixq")'::jsonpath;
Fix bogus handling of XQuery regex option flags. The SQL spec defers to XQuery to define what the option flags are for LIKE_REGEX patterns. XQuery says that: * 's' allows the dot character to match newlines, which by default it will not; * 'm' allows ^ and $ to match at newlines, not only at the start/end of the whole string. Thus, these are *not* inverses as they are for the similarly-named POSIX options, and neither one corresponds to the POSIX 'n' option. Fortunately, Spencer's library does expose these two behaviors as separately twiddlable flags, so we just have to fix the mapping from JSP flag bits to REG flag bits. I also chose to rename the symbol for 's' to DOTALL, to make it clearer that it's not the inverse of MLINE. Also, XQuery says that if the 'q' flag "is used together with the m, s, or x flag, that flag has no effect". I read this as saying that 'q' overrides the other flags; whoever wrote our code seems to have read it backwards. Lastly, while XQuery's 'x' flag is related to what Spencer's code does for REG_EXPANDED, it's not the same or a subset. It seems best to treat XQuery's 'x' as unimplemented for now. Maybe later we can expand our regex code to offer 'x'-style parsing as a separate option. While at it, refactor the jsonpath code so that (a) there's only one copy of the flag transformation logic not two, and (b) the processing of flags is independent of the order in which the flags are written. We need some documentation updates to go with this, but I'll tackle that separately. Back-patch to v12 where this code originated. Discussion: https://postgr.es/m/CAPpHfdvDci4iqNF9fhRkTqhe-5_8HmzeLt56drH%2B_Rv2rNRqfg@mail.gmail.com Reference: https://www.w3.org/TR/2017/REC-xpath-functions-31-20170321/#flags
2019-09-17 21:39:51 +02:00
jsonpath
-----------------------------------------
$?(@ like_regex "pattern" flag "ismxq")
(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 '$ ? (@ like_regex "pattern" flag "a")'::jsonpath;
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;
^
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")))
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
(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;
jsonpath
-----------------
$?(@."a" < 0.1)
(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 '$ ? (@.a < -.1)'::jsonpath;
jsonpath
------------------
$?(@."a" < -0.1)
(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 '$ ? (@.a < +.1)'::jsonpath;
jsonpath
-----------------
$?(@."a" < 0.1)
(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 '$ ? (@.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;
jsonpath
---------------
$?(@."a" < 1)
(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 '$ ? (@.a < -.1e1)'::jsonpath;
jsonpath
----------------
$?(@."a" < -1)
(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 '$ ? (@.a < +.1e1)'::jsonpath;
jsonpath
---------------
$?(@."a" < 1)
(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 '$ ? (@.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;
jsonpath
------------------
$?(@."a" < 0.01)
(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 '$ ? (@.a < -.1e-1)'::jsonpath;
jsonpath
-------------------
$?(@."a" < -0.01)
(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 '$ ? (@.a < +.1e-1)'::jsonpath;
jsonpath
------------------
$?(@."a" < 0.01)
(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 '$ ? (@.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;
jsonpath
---------------
$?(@."a" < 1)
(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 '$ ? (@.a < -.1e+1)'::jsonpath;
jsonpath
----------------
$?(@."a" < -1)
(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 '$ ? (@.a < +.1e+1)'::jsonpath;
jsonpath
---------------
$?(@."a" < 1)
(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 '$ ? (@.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)
-- numeric literals
select '0'::jsonpath;
jsonpath
----------
0
(1 row)
select '00'::jsonpath;
ERROR: trailing junk after numeric literal at or near "00" of jsonpath input
LINE 1: select '00'::jsonpath;
^
select '0755'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '0755'::jsonpath;
^
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 '.001'::jsonpath;
jsonpath
----------
0.001
(1 row)
select '.001e1'::jsonpath;
jsonpath
----------
0.01
(1 row)
select '1.'::jsonpath;
jsonpath
----------
1
(1 row)
select '1.e1'::jsonpath;
jsonpath
----------
10
(1 row)
select '1a'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1a" of jsonpath input
LINE 1: select '1a'::jsonpath;
^
select '1e'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1e" of jsonpath input
LINE 1: select '1e'::jsonpath;
^
select '1.e'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1.e" of jsonpath input
LINE 1: select '1.e'::jsonpath;
^
select '1.2a'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1.2a" of jsonpath input
LINE 1: select '1.2a'::jsonpath;
^
select '1.2e'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1.2e" of jsonpath input
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
----------
1000
(1 row)
select '1.e3.e'::jsonpath;
jsonpath
------------
(1000)."e"
(1 row)
select '1.e3.e4'::jsonpath;
jsonpath
-------------
(1000)."e4"
(1 row)
select '1.2e3'::jsonpath;
jsonpath
----------
1200
(1 row)
select '1.2e3a'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1.2e3a" of jsonpath input
LINE 1: select '1.2e3a'::jsonpath;
^
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;
jsonpath
----------
(1)."e"
(1 row)
select '1..e3'::jsonpath;
jsonpath
----------
(1)."e3"
(1 row)
select '(1.).e'::jsonpath;
jsonpath
----------
(1)."e"
(1 row)
select '(1.).e3'::jsonpath;
jsonpath
----------
(1)."e3"
(1 row)
select '1?(2>3)'::jsonpath;
jsonpath
-------------
(1)?(2 > 3)
(1 row)
-- nondecimal
select '0b100101'::jsonpath;
jsonpath
----------
37
(1 row)
select '0o273'::jsonpath;
jsonpath
----------
187
(1 row)
select '0x42F'::jsonpath;
jsonpath
----------
1071
(1 row)
-- error cases
select '0b'::jsonpath;
ERROR: trailing junk after numeric literal at or near "0b" of jsonpath input
LINE 1: select '0b'::jsonpath;
^
select '1b'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1b" of jsonpath input
LINE 1: select '1b'::jsonpath;
^
select '0b0x'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '0b0x'::jsonpath;
^
select '0o'::jsonpath;
ERROR: trailing junk after numeric literal at or near "0o" of jsonpath input
LINE 1: select '0o'::jsonpath;
^
select '1o'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1o" of jsonpath input
LINE 1: select '1o'::jsonpath;
^
select '0o0x'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '0o0x'::jsonpath;
^
select '0x'::jsonpath;
ERROR: trailing junk after numeric literal at or near "0x" of jsonpath input
LINE 1: select '0x'::jsonpath;
^
select '1x'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1x" of jsonpath input
LINE 1: select '1x'::jsonpath;
^
select '0x0y'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '0x0y'::jsonpath;
^
-- underscores
select '1_000_000'::jsonpath;
jsonpath
----------
1000000
(1 row)
select '1_2_3'::jsonpath;
jsonpath
----------
123
(1 row)
select '0x1EEE_FFFF'::jsonpath;
jsonpath
-----------
518979583
(1 row)
select '0o2_73'::jsonpath;
jsonpath
----------
187
(1 row)
select '0b10_0101'::jsonpath;
jsonpath
----------
37
(1 row)
select '1_000.000_005'::jsonpath;
jsonpath
-------------
1000.000005
(1 row)
select '1_000.'::jsonpath;
jsonpath
----------
1000
(1 row)
select '.000_005'::jsonpath;
jsonpath
----------
0.000005
(1 row)
select '1_000.5e0_1'::jsonpath;
jsonpath
----------
10005
(1 row)
-- error cases
select '_100'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '_100'::jsonpath;
^
select '100_'::jsonpath;
ERROR: trailing junk after numeric literal at or near "100_" of jsonpath input
LINE 1: select '100_'::jsonpath;
^
select '100__000'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '100__000'::jsonpath;
^
select '_1_000.5'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '_1_000.5'::jsonpath;
^
select '1_000_.5'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1_000_" of jsonpath input
LINE 1: select '1_000_.5'::jsonpath;
^
select '1_000._5'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1_000._" of jsonpath input
LINE 1: select '1_000._5'::jsonpath;
^
select '1_000.5_'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1_000.5_" of jsonpath input
LINE 1: select '1_000.5_'::jsonpath;
^
select '1_000.5e_1'::jsonpath;
ERROR: trailing junk after numeric literal at or near "1_000.5e" of jsonpath input
LINE 1: select '1_000.5e_1'::jsonpath;
^
-- underscore after prefix not allowed in JavaScript (but allowed in SQL)
select '0b_10_0101'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '0b_10_0101'::jsonpath;
^
select '0o_273'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '0o_273'::jsonpath;
^
select '0x_42F'::jsonpath;
ERROR: syntax error at end of jsonpath input
LINE 1: select '0x_42F'::jsonpath;
^
-- test non-error-throwing API
SELECT str as jsonpath,
pg_input_is_valid(str,'jsonpath') as ok,
errinfo.sql_error_code,
errinfo.message,
errinfo.detail,
errinfo.hint
FROM unnest(ARRAY['$ ? (@ like_regex "pattern" flag "smixq")'::text,
'$ ? (@ like_regex "pattern" flag "a")',
'@ + 1',
'00',
'1a']) str,
LATERAL pg_input_error_info(str, 'jsonpath') as errinfo;
jsonpath | ok | sql_error_code | message | detail | hint
-------------------------------------------+----+----------------+-----------------------------------------------------------------------+----------------------------------------------------------+------
$ ? (@ like_regex "pattern" flag "smixq") | t | | | |
$ ? (@ like_regex "pattern" flag "a") | f | 42601 | invalid input syntax for type jsonpath | Unrecognized flag character "a" in LIKE_REGEX predicate. |
@ + 1 | f | 42601 | @ is not allowed in root expressions | |
00 | f | 42601 | trailing junk after numeric literal at or near "00" of jsonpath input | |
1a | f | 42601 | trailing junk after numeric literal at or near "1a" of jsonpath input | |
(5 rows)