diff --git a/src/dialect/snowflake.rs b/src/dialect/snowflake.rs index 116255f8e..59cafe653 100644 --- a/src/dialect/snowflake.rs +++ b/src/dialect/snowflake.rs @@ -132,7 +132,24 @@ impl Dialect for SnowflakeDialect { fn parse_statement(&self, parser: &mut Parser) -> Option> { if parser.parse_keyword(Keyword::BEGIN) { - return Some(parser.parse_begin_exception_end()); + // Allow standalone BEGIN; for Snowflake + match &parser.peek_token_ref().token { + Token::SemiColon | Token::EOF => { + return Some(Ok(Statement::StartTransaction { + modes: Default::default(), + begin: true, + transaction: None, + modifier: None, + statements: vec![], + exception: None, + has_end_keyword: false, + })) + } + _ => { + // BEGIN ... [EXCEPTION] ... END block + return Some(parser.parse_begin_exception_end()); + } + } } if parser.parse_keywords(&[Keyword::ALTER, Keyword::SESSION]) { diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index 5c6fb6231..d1719dd43 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs @@ -4343,6 +4343,40 @@ fn test_snowflake_fetch_clause_syntax() { ); } +#[test] +fn test_snowflake_begin_standalone() { + // BEGIN; (no END) should be allowed for Snowflake + let mut stmts = snowflake().parse_sql_statements("BEGIN;").unwrap(); + assert_eq!(1, stmts.len()); + match stmts.remove(0) { + Statement::StartTransaction { + begin, + has_end_keyword, + statements, + .. + } => { + assert!(begin); + assert!(!has_end_keyword); + assert!(statements.is_empty()); + } + other => panic!("unexpected stmt: {other:?}"), + } +} + +#[test] +fn test_snowflake_begin_commit_sequence() { + let mut stmts = snowflake().parse_sql_statements("BEGIN; COMMIT;").unwrap(); + assert_eq!(2, stmts.len()); + match stmts.remove(0) { + Statement::StartTransaction { begin, .. } => assert!(begin), + other => panic!("unexpected first stmt: {other:?}"), + } + match stmts.remove(0) { + Statement::Commit { end, .. } => assert!(!end), + other => panic!("unexpected second stmt: {other:?}"), + } +} + #[test] fn test_snowflake_create_view_with_multiple_column_options() { let create_view_with_tag =