Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,24 @@ impl Dialect for SnowflakeDialect {

fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
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]) {
Expand Down
34 changes: 34 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down