Skip to content

Commit 2bf08db

Browse files
committed
fixup: make NOTNULL/NOT NULL an alias for Expr::IsNotNull
1 parent f022dfa commit 2bf08db

File tree

4 files changed

+18
-41
lines changed

4 files changed

+18
-41
lines changed

src/ast/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,6 @@ pub enum Expr {
756756
IsNull(Box<Expr>),
757757
/// `IS NOT NULL` operator
758758
IsNotNull(Box<Expr>),
759-
/// `NOTNULL` or `NOT NULL` operator
760-
NotNull {
761-
expr: Box<Expr>,
762-
/// true if `NOT NULL`, false if `NOTNULL`
763-
with_space: bool,
764-
},
765759
/// `IS UNKNOWN` operator
766760
IsUnknown(Box<Expr>),
767761
/// `IS NOT UNKNOWN` operator
@@ -1436,12 +1430,6 @@ impl fmt::Display for Expr {
14361430
Expr::IsNotFalse(ast) => write!(f, "{ast} IS NOT FALSE"),
14371431
Expr::IsNull(ast) => write!(f, "{ast} IS NULL"),
14381432
Expr::IsNotNull(ast) => write!(f, "{ast} IS NOT NULL"),
1439-
Expr::NotNull { expr, with_space } => write!(
1440-
f,
1441-
"{} {}",
1442-
expr,
1443-
if *with_space { "NOT NULL" } else { "NOTNULL" }
1444-
),
14451433
Expr::IsUnknown(ast) => write!(f, "{ast} IS UNKNOWN"),
14461434
Expr::IsNotUnknown(ast) => write!(f, "{ast} IS NOT UNKNOWN"),
14471435
Expr::InList {

src/ast/spans.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,6 @@ impl Spanned for Expr {
14371437
Expr::IsNotTrue(expr) => expr.span(),
14381438
Expr::IsNull(expr) => expr.span(),
14391439
Expr::IsNotNull(expr) => expr.span(),
1440-
Expr::NotNull { expr, .. } => expr.span(),
14411440
Expr::IsUnknown(expr) => expr.span(),
14421441
Expr::IsNotUnknown(expr) => expr.span(),
14431442
Expr::IsDistinctFrom(lhs, rhs) => lhs.span().union(&rhs.span()),

src/parser/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,10 +3574,7 @@ impl<'a> Parser<'a> {
35743574
regexp,
35753575
})
35763576
} else if dialect.supports_is_not_null_alias(NotSpaceNull) && negated && null {
3577-
Ok(Expr::NotNull {
3578-
expr: Box::new(expr),
3579-
with_space: true,
3580-
})
3577+
Ok(Expr::IsNotNull(Box::new(expr)))
35813578
} else if self.parse_keyword(Keyword::IN) {
35823579
self.parse_in(expr, negated)
35833580
} else if self.parse_keyword(Keyword::BETWEEN) {
@@ -3616,10 +3613,7 @@ impl<'a> Parser<'a> {
36163613
}
36173614
}
36183615
Keyword::NOTNULL if dialect.supports_is_not_null_alias(NotNull) => {
3619-
Ok(Expr::NotNull {
3620-
expr: Box::new(expr),
3621-
with_space: false,
3622-
})
3616+
Ok(Expr::IsNotNull(Box::new(expr)))
36233617
}
36243618
Keyword::MEMBER => {
36253619
if self.parse_keyword(Keyword::OF) {

tests/sqlparser_common.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15991,11 +15991,12 @@ fn parse_not_null_unsupported() {
1599115991

1599215992
#[test]
1599315993
fn parse_not_null_supported() {
15994-
// DuckDB and SQLite support `x NOT NULL` as an expression
15994+
// DuckDB and SQLite support `x NOT NULL` as an alias for `x IS NOT NULL`
1599515995
let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOT NULL FROM t"#;
15996+
let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x IS NOT NULL FROM t"#;
1599615997
let dialects =
1599715998
all_dialects_where(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotSpaceNull));
15998-
let stmt = dialects.one_statement_parses_to(sql, sql);
15999+
let stmt = dialects.one_statement_parses_to(sql, canonical);
1599916000
match stmt {
1600016001
Statement::Query(qry) => match *qry.body {
1600116002
SetExpr::Select(select) => {
@@ -16008,14 +16009,11 @@ fn parse_not_null_supported() {
1600816009
};
1600916010
assert_eq!(
1601016011
*expr,
16011-
Expr::NotNull {
16012-
expr: Box::new(Identifier(Ident {
16013-
value: "x".to_string(),
16014-
quote_style: None,
16015-
span: fake_span,
16016-
})),
16017-
with_space: true,
16018-
},
16012+
Expr::IsNotNull(Box::new(Identifier(Ident {
16013+
value: "x".to_string(),
16014+
quote_style: None,
16015+
span: fake_span,
16016+
})),),
1601916017
);
1602016018
}
1602116019
_ => unreachable!(),
@@ -16074,10 +16072,11 @@ fn parse_notnull_unsupported() {
1607416072

1607516073
#[test]
1607616074
fn parse_notnull_supported() {
16077-
// DuckDB and SQLite support `x NOT NULL` as an expression
16075+
// Postgres, DuckDB and SQLite support `x NOTNULL` as an alias for `x IS NOT NULL`
1607816076
let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOTNULL FROM t"#;
16077+
let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x IS NOT NULL FROM t"#;
1607916078
let dialects = all_dialects_where(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotNull));
16080-
let stmt = dialects.one_statement_parses_to(sql, "");
16079+
let stmt = dialects.one_statement_parses_to(sql, canonical);
1608116080
match stmt {
1608216081
Statement::Query(qry) => match *qry.body {
1608316082
SetExpr::Select(select) => {
@@ -16090,14 +16089,11 @@ fn parse_notnull_supported() {
1609016089
};
1609116090
assert_eq!(
1609216091
*expr,
16093-
Expr::NotNull {
16094-
expr: Box::new(Identifier(Ident {
16095-
value: "x".to_string(),
16096-
quote_style: None,
16097-
span: fake_span,
16098-
})),
16099-
with_space: false,
16100-
},
16092+
Expr::IsNotNull(Box::new(Identifier(Ident {
16093+
value: "x".to_string(),
16094+
quote_style: None,
16095+
span: fake_span,
16096+
})),),
1610116097
);
1610216098
}
1610316099
_ => unreachable!(),

0 commit comments

Comments
 (0)