Add support for NOT NULL and NOTNULL expressions (#1927)

Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
Ryan Schneider 2025-07-21 03:58:20 -07:00 committed by GitHub
parent 23f40cdc40
commit a73577c29f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 200 additions and 8 deletions

View file

@ -16040,6 +16040,27 @@ fn parse_create_procedure_with_parameter_modes() {
}
}
#[test]
fn parse_not_null() {
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");
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,
..
}
);
}
#[test]
fn test_select_exclude() {
let dialects = all_dialects_where(|d| d.supports_select_wildcard_exclude());
@ -16183,3 +16204,29 @@ fn test_identifier_unicode_start() {
]);
let _ = dialects.verified_stmt(sql);
}
#[test]
fn parse_notnull() {
// Some dialects support `x NOTNULL` as an expression while others consider
// `x NOTNULL` like `x AS NOTNULL` and thus consider `NOTNULL` an alias for x.
let notnull_unsupported_dialects = all_dialects_except(|d| d.supports_notnull_operator());
let _ = notnull_unsupported_dialects
.verified_only_select_with_canonical("SELECT NULL NOTNULL", "SELECT NULL AS NOTNULL");
// Supported dialects consider `x NOTNULL` as an alias for `x IS NOT NULL`
let notnull_supported_dialects = all_dialects_where(|d| d.supports_notnull_operator());
let _ = notnull_supported_dialects.expr_parses_to("x NOTNULL", "x IS NOT NULL");
// For dialects which support it, `NOT NULL NOTNULL` should
// parse as `(NOT (NULL IS NOT NULL))`
assert_matches!(
notnull_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`
notnull_unsupported_dialects.expr_parses_to("NOT NULL NOTNULL", "NOT NULL");
}