Remove ambiguity for jsonb_path_match() and jsonb_path_exists()
authorAlexander Korotkov <akorotkov@postgresql.org>
Wed, 20 Mar 2019 07:27:56 +0000 (10:27 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Wed, 20 Mar 2019 07:30:56 +0000 (10:30 +0300)
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
src/include/catalog/pg_operator.dat
src/include/catalog/pg_proc.dat
src/test/regress/expected/jsonb_jsonpath.out
src/test/regress/sql/jsonb_jsonpath.sql

index f896653f4d41d2f9f826a536150e16122776e6a1..917e91c90dcb58f038f8503a50e32c47fdbb7b3d 100644 (file)
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     201903161
+#define CATALOG_VERSION_NO     201903201
 
 #endif
index ad8c5bb30e9a8856a2a2399e13988ebde994a319..bacafa518390d999640f94e4113b4e6f388885f9 100644 (file)
   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' },
 
 ]
index 84120de3620f32c9bbfe56d88c3cb5575499f988..acf1131b521a68a7de0624effac09b8b6420ee92 100644 (file)
   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
index 0e2e2c474c06968356890662ae4315a1ad360293..e604bae6a3f19d6818146be995d01bae9d37b674 100644 (file)
@@ -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)
+
index b56f8872ae81bc3786c5f4b87601cd0461aa8885..41b346b2d4de77b11fb6cfbb265c17e6e87fc99a 100644 (file)
@@ -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');