Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ impl Dialect for SnowflakeDialect {

fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
if parser.parse_keyword(Keyword::BEGIN) {
// Snowflake supports both `BEGIN TRANSACTION` and `BEGIN ... END` blocks.
// If the next keyword indicates a transaction statement, let the
// standard parse_begin() handle it.
if parser.peek_keyword(Keyword::TRANSACTION)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use parser.peek_one_of_keywords() and parser.peek_token_ref() for the two cases to simplify or make the op less expensive?

|| parser.peek_keyword(Keyword::WORK)
|| parser.peek_keyword(Keyword::NAME)
|| parser.peek_token().token == Token::SemiColon
|| parser.peek_token().token == Token::EOF
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a test case with only a begin keyword (for the EOF case)?

{
parser.prev_token();
return None;
}
return Some(parser.parse_begin_exception_end());
}

Expand Down
18 changes: 18 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4610,6 +4610,24 @@ END
assert_eq!(2, exception[1].statements.len());
}

#[test]
fn test_begin_transaction() {
snowflake().verified_stmt("BEGIN TRANSACTION");
snowflake().verified_stmt("BEGIN WORK");

// BEGIN TRANSACTION with statements
let stmts = snowflake()
.parse_sql_statements("BEGIN TRANSACTION; DROP TABLE IF EXISTS bla; COMMIT")
.unwrap();
assert_eq!(3, stmts.len());

// Bare BEGIN (no TRANSACTION keyword) with statements
let stmts = snowflake()
.parse_sql_statements("BEGIN; DROP TABLE IF EXISTS bla; COMMIT")
.unwrap();
assert_eq!(3, stmts.len());
}

#[test]
fn test_snowflake_fetch_clause_syntax() {
let canonical = "SELECT c1 FROM fetch_test FETCH FIRST 2 ROWS ONLY";
Expand Down