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