From 641fde25233ef3ecc3b8101fe287eea9fceba6fd Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Wed, 20 Mar 2019 10:27:56 +0300 Subject: [PATCH] Remove ambiguity for jsonb_path_match() and jsonb_path_exists() There are 2-arguments and 4-arguments versions of jsonb_path_match() and jsonb_path_exists(). But 4-arguments versions have optional 3rd and 4th arguments, that leads to ambiguity. In the same time 2-arguments versions are needed only for @@ and @? operators. So, rename 2-arguments versions to remove the ambiguity. Catversion is bumped. --- src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_operator.dat | 4 ++-- src/include/catalog/pg_proc.dat | 4 ++-- src/test/regress/expected/jsonb_jsonpath.out | 12 ++++++++++++ src/test/regress/sql/jsonb_jsonpath.sql | 2 ++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index f896653f4d..917e91c90d 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201903161 +#define CATALOG_VERSION_NO 201903201 #endif diff --git a/src/include/catalog/pg_operator.dat b/src/include/catalog/pg_operator.dat index ad8c5bb30e..bacafa5183 100644 --- a/src/include/catalog/pg_operator.dat +++ b/src/include/catalog/pg_operator.dat @@ -3257,11 +3257,11 @@ oprresult => 'jsonb', oprcode => 'jsonb_delete_path' }, { oid => '4012', descr => 'jsonpath exists', oprname => '@?', oprleft => 'jsonb', oprright => 'jsonpath', - oprresult => 'bool', oprcode => 'jsonb_path_exists(jsonb,jsonpath)', + oprresult => 'bool', oprcode => 'jsonb_path_exists_opr(jsonb,jsonpath)', oprrest => 'contsel', oprjoin => 'contjoinsel' }, { oid => '4013', descr => 'jsonpath match', oprname => '@@', oprleft => 'jsonb', oprright => 'jsonpath', - oprresult => 'bool', oprcode => 'jsonb_path_match(jsonb,jsonpath)', + oprresult => 'bool', oprcode => 'jsonb_path_match_opr(jsonb,jsonpath)', oprrest => 'contsel', oprjoin => 'contjoinsel' }, ] diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 84120de362..acf1131b52 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -9249,10 +9249,10 @@ prosrc => 'jsonb_path_match' }, { oid => '4010', descr => 'implementation of @? operator', - proname => 'jsonb_path_exists', prorettype => 'bool', + proname => 'jsonb_path_exists_opr', prorettype => 'bool', proargtypes => 'jsonb jsonpath', prosrc => 'jsonb_path_exists_opr' }, { oid => '4011', descr => 'implementation of @@ operator', - proname => 'jsonb_path_match', prorettype => 'bool', + proname => 'jsonb_path_match_opr', prorettype => 'bool', proargtypes => 'jsonb jsonpath', prosrc => 'jsonb_path_match_opr' }, # txid diff --git a/src/test/regress/expected/jsonb_jsonpath.out b/src/test/regress/expected/jsonb_jsonpath.out index 0e2e2c474c..e604bae6a3 100644 --- a/src/test/regress/expected/jsonb_jsonpath.out +++ b/src/test/regress/expected/jsonb_jsonpath.out @@ -1751,6 +1751,12 @@ SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*] ? (@.a > 2)'; f (1 row) +SELECT jsonb_path_exists('[{"a": 1}, {"a": 2}]', '$[*].a ? (@ > 1)'); + jsonb_path_exists +------------------- + t +(1 row) + SELECT jsonb_path_exists('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', vars => '{"min": 1, "max": 4}'); jsonb_path_exists ------------------- @@ -1775,3 +1781,9 @@ SELECT jsonb '[{"a": 1}, {"a": 2}]' @@ '$[*].a > 2'; f (1 row) +SELECT jsonb_path_match('[{"a": 1}, {"a": 2}]', '$[*].a > 1'); + jsonb_path_match +------------------ + t +(1 row) + diff --git a/src/test/regress/sql/jsonb_jsonpath.sql b/src/test/regress/sql/jsonb_jsonpath.sql index b56f8872ae..41b346b2d4 100644 --- a/src/test/regress/sql/jsonb_jsonpath.sql +++ b/src/test/regress/sql/jsonb_jsonpath.sql @@ -362,8 +362,10 @@ SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*]. SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*].a ? (@ > 1)'; SELECT jsonb '[{"a": 1}, {"a": 2}]' @? '$[*] ? (@.a > 2)'; +SELECT jsonb_path_exists('[{"a": 1}, {"a": 2}]', '$[*].a ? (@ > 1)'); SELECT jsonb_path_exists('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', vars => '{"min": 1, "max": 4}'); SELECT jsonb_path_exists('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*] ? (@.a > $min && @.a < $max)', vars => '{"min": 3, "max": 4}'); SELECT jsonb '[{"a": 1}, {"a": 2}]' @@ '$[*].a > 1'; SELECT jsonb '[{"a": 1}, {"a": 2}]' @@ '$[*].a > 2'; +SELECT jsonb_path_match('[{"a": 1}, {"a": 2}]', '$[*].a > 1');