Skip to content

Adding support for IS JSON & IS NOT JSON - #2256

Merged
iffyio merged 1 commit into
apache:mainfrom
LucaCappelletti94:postgres-regression-12
Jul 27, 2026
Merged

Adding support for IS JSON & IS NOT JSON#2256
iffyio merged 1 commit into
apache:mainfrom
LucaCappelletti94:postgres-regression-12

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

This PR adds support for the SQL/JSON predicate syntax expression IS [NOT] JSON [VALUE|SCALAR|ARRAY|OBJECT] [WITH|WITHOUT UNIQUE [KEYS]], aligning with the SQL/JSON testing syntax documented by PostgreSQL (JSON Functions and Operators, Table 9.50) and Oracle (SQL/JSON Conditions IS JSON and IS NOT JSON).

Implementation-wise, it introduces Expr::IsJson plus JsonPredicateType and JsonKeyUniqueness in the AST, parses the full optional modifier chain, and gates support behind a new dialect capability (supports_is_json_predicate()) enabled for Generic, ANSI, PostgreSQL, and Oracle so unsupported dialect behavior and hints remain explicit. I have included ANSI as this method in theory was introduced there in 2016.

We also accept optional KEYS (canonicalizing to include it on display) and added coverage for both IS JSON and IS NOT JSON, malformed/junk inputs, and duplicate uniqueness clauses.

@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review February 27, 2026 21:41
@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.

@github-actions github-actions Bot added the Stale label Apr 29, 2026
@LucaCappelletti94
LucaCappelletti94 force-pushed the postgres-regression-12 branch from 3014f8c to c0e0131 Compare May 4, 2026 18:23
@github-actions github-actions Bot removed the Stale label May 5, 2026
@LucaCappelletti94
LucaCappelletti94 force-pushed the postgres-regression-12 branch 2 times, most recently from 6fcef30 to 411f7ba Compare July 26, 2026 08:13
@LucaCappelletti94

Copy link
Copy Markdown
Contributor Author

@iffyio I have refactored this PR also in line of the permissive approach you have suggested for #2356

Comment thread tests/sqlparser_common.rs Outdated
let cases = [
(
"SELECT * FROM t WHERE a IS JSON WITH FROM",
&["Expected: UNIQUE", "found: FROM"][..],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we drop the exact match on the error message (they tend to change as new features are added or code is refactored) and only assert that we get a parse failure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also simplified the other analogous error matching that pre-existed and overlapped with the current edit.

Comment thread tests/sqlparser_common.rs Outdated
}

#[test]
fn parse_is_json_predicate_negative() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn parse_is_json_predicate_negative() {
fn parse_is_json_predicate_invalid() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread tests/sqlparser_common.rs Outdated
fn parse_is_json_predicate() {
use self::Expr::*;

let sql = "a IS JSON";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we simplify the tests a bit since the struct assertions have a lot of overlap we can have most of them only rely on the roundtrip verified_expr - I imagine it would suffice to only have one of the scenarios assert the returned struct

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed down

@iffyio iffyio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @LucaCappelletti94!

@iffyio
iffyio added this pull request to the merge queue Jul 27, 2026
Merged via the queue into apache:main with commit 797fc9b Jul 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants