-
Notifications
You must be signed in to change notification settings - Fork 668
Add support for NOT NULL
and NOTNULL
expressions
#1927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
3b5cdce
fe51680
ab5c571
75ba821
4009fa7
ab6607b
375fe8c
40abd90
45fff12
bf25f42
bc454c6
b7d4e1e
7371bff
1466e2a
0c56a51
8b376b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,6 +608,7 @@ define_keywords!( | |
NOT, | ||
NOTHING, | ||
NOTIFY, | ||
NOTNULL, | ||
NOWAIT, | ||
NO_WRITE_TO_BINLOG, | ||
NTH_VALUE, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16031,6 +16031,30 @@ fn parse_create_procedure_with_parameter_modes() { | |
} | ||
} | ||
|
||
#[test] | ||
fn parse_not_null_supported() { | ||
let _ = all_dialects().expr_parses_to("x NOT NULL", "x IS NOT NULL"); | ||
let _ = all_dialects().expr_parses_to("NULL NOT NULL", "NULL IS NOT NULL"); | ||
} | ||
|
||
#[test] | ||
fn test_not_null_precedence() { | ||
assert_matches!( | ||
all_dialects().expr_parses_to("NOT NULL NOT NULL", "NOT NULL IS NOT NULL"), | ||
Expr::UnaryOp { | ||
op: UnaryOperator::Not, | ||
.. | ||
} | ||
); | ||
assert_matches!( | ||
all_dialects().expr_parses_to("NOT x NOT NULL", "NOT x IS NOT NULL"), | ||
Expr::UnaryOp { | ||
op: UnaryOperator::Not, | ||
.. | ||
} | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the |
||
|
||
#[test] | ||
fn test_select_exclude() { | ||
let dialects = all_dialects_where(|d| d.supports_select_wildcard_exclude()); | ||
|
@@ -16174,3 +16198,39 @@ fn test_identifier_unicode_start() { | |
]); | ||
let _ = dialects.verified_stmt(sql); | ||
} | ||
|
||
#[test] | ||
fn parse_notnull_unsupported() { | ||
// Only Postgres, DuckDB, and SQLite support `x NOTNULL` as an expression | ||
// All other dialects consider `x NOTNULL` like `x AS NOTNULL` and thus | ||
// consider `NOTNULL` an alias for x. | ||
let dialects = all_dialects_except(|d| d.supports_notnull_operator()); | ||
let _ = dialects | ||
.verified_only_select_with_canonical("SELECT NULL NOTNULL", "SELECT NULL AS NOTNULL"); | ||
} | ||
|
||
#[test] | ||
fn parse_notnull_supported() { | ||
// Postgres, DuckDB and SQLite support `x NOTNULL` as an alias for `x IS NOT NULL` | ||
let dialects = all_dialects_where(|d| d.supports_notnull_operator()); | ||
let _ = dialects.expr_parses_to("x NOTNULL", "x IS NOT NULL"); | ||
} | ||
|
||
#[test] | ||
fn test_notnull_precedence() { | ||
// For dialects which support it, `NOT NULL NOTNULL` should | ||
// parse as `(NOT (NULL IS NOT NULL))` | ||
let supported_dialects = all_dialects_where(|d| d.supports_notnull_operator()); | ||
let unsupported_dialects = all_dialects_except(|d| d.supports_notnull_operator()); | ||
|
||
assert_matches!( | ||
supported_dialects.expr_parses_to("NOT NULL NOTNULL", "NOT NULL IS NOT NULL"), | ||
Expr::UnaryOp { | ||
op: UnaryOperator::Not, | ||
.. | ||
} | ||
); | ||
|
||
// for unsupported dialects, parsing should stop at `NOT NULL` | ||
unsupported_dialects.expr_parses_to("NOT NULL NOTNULL", "NOT NULL"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since they're the same feature, can we merge these scenarios into the same Also for the comments, ideally we skip mentioning the individual dialects (Postgres, duckdb etc), so that the comment doesnt' become stale as other/new dialects are extended with support for this feature. |
Uh oh!
There was an error while loading. Please reload this page.