Skip to content

Commit 063edc4

Browse files
committed
builtins: add jsonb_path_match
This commit adds the `jsonb_path_match` function, which returns a boolean that evaluates the predicate query, and returns null if the query result isn't a predicate. Release note (sql change): Add the `jsonb_path_match` function, which returns the result of a predicate query.
1 parent fde1949 commit 063edc4

File tree

14 files changed

+204
-4
lines changed

14 files changed

+204
-4
lines changed

docs/generated/sql/functions.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,29 @@ argument is true, the function suppresses the following errors:
12801280
missing object field or array element, unexpected JSON item type,
12811281
datetime and numeric errors.</p>
12821282
</span></td><td>Immutable</td></tr>
1283+
<tr><td><a name="jsonb_path_match"></a><code>jsonb_path_match(target: jsonb, path: jsonpath) &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>Returns the SQL boolean result of a JSON path predicate check
1284+
for the specified JSON value. (This is useful only with predicate check
1285+
expressions, not SQL-standard JSON path expressions, since it will
1286+
either fail or return NULL if the path result is not a single boolean
1287+
value.)</p>
1288+
</span></td><td>Immutable</td></tr>
1289+
<tr><td><a name="jsonb_path_match"></a><code>jsonb_path_match(target: jsonb, path: jsonpath, vars: jsonb) &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>Returns the SQL boolean result of a JSON path predicate check
1290+
for the specified JSON value. (This is useful only with predicate check
1291+
expressions, not SQL-standard JSON path expressions, since it will
1292+
either fail or return NULL if the path result is not a single boolean
1293+
value.) The vars argument must be a JSON object, and its fields provide
1294+
named values to be substituted into the jsonpath expression.</p>
1295+
</span></td><td>Immutable</td></tr>
1296+
<tr><td><a name="jsonb_path_match"></a><code>jsonb_path_match(target: jsonb, path: jsonpath, vars: jsonb, silent: <a href="bool.html">bool</a>) &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>Returns the SQL boolean result of a JSON path predicate check
1297+
for the specified JSON value. (This is useful only with predicate check
1298+
expressions, not SQL-standard JSON path expressions, since it will
1299+
either fail or return NULL if the path result is not a single boolean
1300+
value.) The vars argument must be a JSON object, and its fields provide
1301+
named values to be substituted into the jsonpath expression. If the
1302+
silent argument is true, the function suppresses the following errors:
1303+
missing object field or array element, unexpected JSON item type,
1304+
datetime and numeric errors.</p>
1305+
</span></td><td>Immutable</td></tr>
12831306
<tr><td><a name="jsonb_path_query"></a><code>jsonb_path_query(target: jsonb, path: jsonpath) &rarr; jsonb</code></td><td><span class="funcdesc"><p>Returns all JSON items returned by the JSON path for the specified JSON value.</p>
12841307
</span></td><td>Immutable</td></tr>
12851308
<tr><td><a name="jsonb_path_query"></a><code>jsonb_path_query(target: jsonb, path: jsonpath, vars: jsonb) &rarr; jsonb</code></td><td><span class="funcdesc"><p>Returns all JSON items returned by the JSON path for the specified JSON value.

pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local-read-committed/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local-repeatable-read/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# LogicTest: !local-mixed-24.3 !local-mixed-25.1
2+
3+
query B
4+
SELECT jsonb_path_match('{}', '1 + 1 == 2');
5+
----
6+
true
7+
8+
query B
9+
SELECT jsonb_path_match('{}', '"abc" starts with "b"');
10+
----
11+
false
12+
13+
query T
14+
SELECT jsonb_path_match('{}', 'strict $', '{}', true);
15+
----
16+
NULL
17+
18+
statement error pgcode 22038 pq: jsonb_path_match\(\): single boolean result is expected
19+
SELECT jsonb_path_match('{}', 'strict $', '{}', false);
20+
21+
query T
22+
SELECT jsonb_path_match('{}', '$', '{}', true);
23+
----
24+
NULL
25+
26+
statement error pgcode 22038 pq: jsonb_path_match\(\): single boolean result is expected
27+
SELECT jsonb_path_match('{}', '$', '{}', false);

pkg/sql/logictest/tests/fakedist-disk/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/tests/fakedist/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/tests/local-legacy-schema-changer/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/logictest/tests/local-vec-off/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)