@@ -15992,129 +15992,33 @@ fn parse_create_procedure_with_parameter_modes() {
15992
15992
#[test]
15993
15993
fn parse_not_null_unsupported() {
15994
15994
// Only DuckDB and SQLite support `x NOT NULL` as an expression
15995
- // All other dialects fail to parse.
15996
- let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOT NULL FROM t"#;
15995
+ // All other dialects fail to parse the `NOT NULL` portion
15997
15996
let dialects =
15998
15997
all_dialects_except(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotSpaceNull));
15999
- let res = dialects.parse_sql_statements(sql);
16000
- assert_eq!(
16001
- ParserError::ParserError("Expected: end of statement, found: NULL".to_string()),
16002
- res.unwrap_err()
16003
- );
15998
+ let _ = dialects.expr_parses_to("x NOT NULL", "x");
16004
15999
}
16005
16000
16006
16001
#[test]
16007
16002
fn parse_not_null_supported() {
16008
16003
// DuckDB and SQLite support `x NOT NULL` as an alias for `x IS NOT NULL`
16009
- 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"#;
16011
16004
let dialects =
16012
16005
all_dialects_where(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotSpaceNull));
16013
- let stmt = dialects.one_statement_parses_to(sql, canonical);
16014
- match stmt {
16015
- Statement::Query(qry) => match *qry.body {
16016
- SetExpr::Select(select) => {
16017
- assert_eq!(select.projection.len(), 1);
16018
- match select.projection.first().unwrap() {
16019
- UnnamedExpr(expr) => {
16020
- let fake_span = Span {
16021
- start: Location { line: 0, column: 0 },
16022
- end: Location { line: 0, column: 0 },
16023
- };
16024
- assert_eq!(
16025
- *expr,
16026
- Expr::IsNotNull(Box::new(Identifier(Ident {
16027
- value: "x".to_string(),
16028
- quote_style: None,
16029
- span: fake_span,
16030
- })),),
16031
- );
16032
- }
16033
- _ => unreachable!(),
16034
- }
16035
- }
16036
- _ => unreachable!(),
16037
- },
16038
- _ => unreachable!(),
16039
- }
16006
+ let _ = dialects.expr_parses_to("x NOT NULL", "x IS NOT NULL");
16040
16007
}
16041
16008
16042
16009
#[test]
16043
16010
fn parse_notnull_unsupported() {
16044
16011
// Only Postgres, DuckDB, and SQLite support `x NOTNULL` as an expression
16045
16012
// All other dialects consider `x NOTNULL` like `x AS NOTNULL` and thus
16046
16013
// consider `NOTNULL` an alias for x.
16047
- let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOTNULL FROM t"#;
16048
- let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x AS NOTNULL FROM t"#;
16049
16014
let dialects = all_dialects_except(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotNull));
16050
- let stmt = dialects.one_statement_parses_to(sql, canonical);
16051
- match stmt {
16052
- Statement::Query(qry) => match *qry.body {
16053
- SetExpr::Select(select) => {
16054
- assert_eq!(select.projection.len(), 1);
16055
- match select.projection.first().unwrap() {
16056
- SelectItem::ExprWithAlias { expr, alias } => {
16057
- let fake_span = Span {
16058
- start: Location { line: 0, column: 0 },
16059
- end: Location { line: 0, column: 0 },
16060
- };
16061
- assert_eq!(
16062
- *expr,
16063
- Identifier(Ident {
16064
- value: "x".to_string(),
16065
- quote_style: None,
16066
- span: fake_span,
16067
- })
16068
- );
16069
- assert_eq!(
16070
- *alias,
16071
- Ident {
16072
- value: "NOTNULL".to_string(),
16073
- quote_style: None,
16074
- span: fake_span,
16075
- }
16076
- );
16077
- }
16078
- _ => unreachable!(),
16079
- }
16080
- }
16081
- _ => unreachable!(),
16082
- },
16083
- _ => unreachable!(),
16084
- }
16015
+ let _ = dialects
16016
+ .verified_only_select_with_canonical("SELECT NULL NOTNULL", "SELECT NULL AS NOTNULL");
16085
16017
}
16086
16018
16087
16019
#[test]
16088
16020
fn parse_notnull_supported() {
16089
16021
// Postgres, DuckDB and SQLite support `x NOTNULL` as an alias for `x IS NOT NULL`
16090
- 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"#;
16092
16022
let dialects = all_dialects_where(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotNull));
16093
- let stmt = dialects.one_statement_parses_to(sql, canonical);
16094
- match stmt {
16095
- Statement::Query(qry) => match *qry.body {
16096
- SetExpr::Select(select) => {
16097
- assert_eq!(select.projection.len(), 1);
16098
- match select.projection.first().unwrap() {
16099
- UnnamedExpr(expr) => {
16100
- let fake_span = Span {
16101
- start: Location { line: 0, column: 0 },
16102
- end: Location { line: 0, column: 0 },
16103
- };
16104
- assert_eq!(
16105
- *expr,
16106
- Expr::IsNotNull(Box::new(Identifier(Ident {
16107
- value: "x".to_string(),
16108
- quote_style: None,
16109
- span: fake_span,
16110
- })),),
16111
- );
16112
- }
16113
- _ => unreachable!(),
16114
- }
16115
- }
16116
- _ => unreachable!(),
16117
- },
16118
- _ => unreachable!(),
16119
- }
16023
+ let _ = dialects.expr_parses_to("x NOTNULL", "x IS NOT NULL");
16120
16024
}
0 commit comments