@@ -15978,129 +15978,33 @@ fn parse_create_procedure_with_parameter_modes() {
1597815978#[test]
1597915979fn parse_not_null_unsupported() {
1598015980 // 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
1598315982 let dialects =
1598415983 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");
1599015985}
1599115986
1599215987#[test]
1599315988fn parse_not_null_supported() {
1599415989 // 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"#;
1599715990 let dialects =
1599815991 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");
1602615993}
1602715994
1602815995#[test]
1602915996fn parse_notnull_unsupported() {
1603015997 // Only Postgres, DuckDB, and SQLite support `x NOTNULL` as an expression
1603115998 // All other dialects consider `x NOTNULL` like `x AS NOTNULL` and thus
1603215999 // 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"#;
1603516000 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");
1607116003}
1607216004
1607316005#[test]
1607416006fn parse_notnull_supported() {
1607516007 // 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"#;
1607816008 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");
1610616010}
0 commit comments