File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -247,6 +247,17 @@ impl Dialect for SnowflakeDialect {
247247
248248 fn parse_statement ( & self , parser : & mut Parser ) -> Option < Result < Statement , ParserError > > {
249249 if parser. parse_keyword ( Keyword :: BEGIN ) {
250+ // Snowflake supports both `BEGIN TRANSACTION` and `BEGIN ... END` blocks.
251+ // If the next keyword indicates a transaction statement, let the
252+ // standard parse_begin() handle it.
253+ if parser
254+ . peek_one_of_keywords ( & [ Keyword :: TRANSACTION , Keyword :: WORK , Keyword :: NAME ] )
255+ . is_some ( )
256+ || matches ! ( parser. peek_token_ref( ) . token, Token :: SemiColon | Token :: EOF )
257+ {
258+ parser. prev_token ( ) ;
259+ return None ;
260+ }
250261 return Some ( parser. parse_begin_exception_end ( ) ) ;
251262 }
252263
Original file line number Diff line number Diff line change @@ -4610,6 +4610,27 @@ END
46104610 assert_eq ! ( 2 , exception[ 1 ] . statements. len( ) ) ;
46114611}
46124612
4613+ #[ test]
4614+ fn test_begin_transaction ( ) {
4615+ snowflake ( ) . verified_stmt ( "BEGIN TRANSACTION" ) ;
4616+ snowflake ( ) . verified_stmt ( "BEGIN WORK" ) ;
4617+
4618+ // BEGIN TRANSACTION with statements
4619+ let stmts = snowflake ( )
4620+ . parse_sql_statements ( "BEGIN TRANSACTION; DROP TABLE IF EXISTS bla; COMMIT" )
4621+ . unwrap ( ) ;
4622+ assert_eq ! ( 3 , stmts. len( ) ) ;
4623+
4624+ // Bare BEGIN (no TRANSACTION keyword) with statements
4625+ let stmts = snowflake ( )
4626+ . parse_sql_statements ( "BEGIN; DROP TABLE IF EXISTS bla; COMMIT" )
4627+ . unwrap ( ) ;
4628+ assert_eq ! ( 3 , stmts. len( ) ) ;
4629+
4630+ // Bare BEGIN at EOF (no semicolon, no TRANSACTION keyword)
4631+ snowflake ( ) . verified_stmt ( "BEGIN" ) ;
4632+ }
4633+
46134634#[ test]
46144635fn test_snowflake_fetch_clause_syntax ( ) {
46154636 let canonical = "SELECT c1 FROM fetch_test FETCH FIRST 2 ROWS ONLY" ;
You can’t perform that action at this time.
0 commit comments