Skip to content

Commit ab5c571

Browse files
committed
fixup: make NOTNULL/NOT NULL an alias for Expr::IsNotNull
1 parent fe51680 commit ab5c571

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
@@ -778,12 +778,6 @@ pub enum Expr {
778778
IsNull(Box<Expr>),
779779
/// `IS NOT NULL` operator
780780
IsNotNull(Box<Expr>),
781-
/// `NOTNULL` or `NOT NULL` operator
782-
NotNull {
783-
expr: Box<Expr>,
784-
/// true if `NOT NULL`, false if `NOTNULL`
785-
with_space: bool,
786-
},
787781
/// `IS UNKNOWN` operator
788782
IsUnknown(Box<Expr>),
789783
/// `IS NOT UNKNOWN` operator
@@ -1458,12 +1452,6 @@ impl fmt::Display for Expr {
14581452
Expr::IsNotFalse(ast) => write!(f, "{ast} IS NOT FALSE"),
14591453
Expr::IsNull(ast) => write!(f, "{ast} IS NULL"),
14601454
Expr::IsNotNull(ast) => write!(f, "{ast} IS NOT NULL"),
1461-
Expr::NotNull { expr, with_space } => write!(
1462-
f,
1463-
"{} {}",
1464-
expr,
1465-
if *with_space { "NOT NULL" } else { "NOTNULL" }
1466-
),
14671455
Expr::IsUnknown(ast) => write!(f, "{ast} IS UNKNOWN"),
14681456
Expr::IsNotUnknown(ast) => write!(f, "{ast} IS NOT UNKNOWN"),
14691457
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
@@ -16005,11 +16005,12 @@ fn parse_not_null_unsupported() {
1600516005

1600616006
#[test]
1600716007
fn parse_not_null_supported() {
16008-
// DuckDB and SQLite support `x NOT NULL` as an expression
16008+
// DuckDB and SQLite support `x NOT NULL` as an alias for `x IS NOT NULL`
1600916009
let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOT NULL FROM t"#;
16010+
let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x IS NOT NULL FROM t"#;
1601016011
let dialects =
1601116012
all_dialects_where(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotSpaceNull));
16012-
let stmt = dialects.one_statement_parses_to(sql, sql);
16013+
let stmt = dialects.one_statement_parses_to(sql, canonical);
1601316014
match stmt {
1601416015
Statement::Query(qry) => match *qry.body {
1601516016
SetExpr::Select(select) => {
@@ -16022,14 +16023,11 @@ fn parse_not_null_supported() {
1602216023
};
1602316024
assert_eq!(
1602416025
*expr,
16025-
Expr::NotNull {
16026-
expr: Box::new(Identifier(Ident {
16027-
value: "x".to_string(),
16028-
quote_style: None,
16029-
span: fake_span,
16030-
})),
16031-
with_space: true,
16032-
},
16026+
Expr::IsNotNull(Box::new(Identifier(Ident {
16027+
value: "x".to_string(),
16028+
quote_style: None,
16029+
span: fake_span,
16030+
})),),
1603316031
);
1603416032
}
1603516033
_ => unreachable!(),
@@ -16088,10 +16086,11 @@ fn parse_notnull_unsupported() {
1608816086

1608916087
#[test]
1609016088
fn parse_notnull_supported() {
16091-
// DuckDB and SQLite support `x NOT NULL` as an expression
16089+
// Postgres, DuckDB and SQLite support `x NOTNULL` as an alias for `x IS NOT NULL`
1609216090
let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOTNULL FROM t"#;
16091+
let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x IS NOT NULL FROM t"#;
1609316092
let dialects = all_dialects_where(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotNull));
16094-
let stmt = dialects.one_statement_parses_to(sql, "");
16093+
let stmt = dialects.one_statement_parses_to(sql, canonical);
1609516094
match stmt {
1609616095
Statement::Query(qry) => match *qry.body {
1609716096
SetExpr::Select(select) => {
@@ -16104,14 +16103,11 @@ fn parse_notnull_supported() {
1610416103
};
1610516104
assert_eq!(
1610616105
*expr,
16107-
Expr::NotNull {
16108-
expr: Box::new(Identifier(Ident {
16109-
value: "x".to_string(),
16110-
quote_style: None,
16111-
span: fake_span,
16112-
})),
16113-
with_space: false,
16114-
},
16106+
Expr::IsNotNull(Box::new(Identifier(Ident {
16107+
value: "x".to_string(),
16108+
quote_style: None,
16109+
span: fake_span,
16110+
})),),
1611516111
);
1611616112
}
1611716113
_ => unreachable!(),

0 commit comments

Comments
 (0)