Skip to content

Commit 2e15b90

Browse files
committed
Only affect snowflake logic
1 parent 4f56f81 commit 2e15b90

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
lines changed

src/dialect/snowflake.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,24 @@ impl Dialect for SnowflakeDialect {
132132

133133
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
134134
if parser.parse_keyword(Keyword::BEGIN) {
135-
return Some(parser.parse_begin_exception_end());
135+
// Allow standalone BEGIN; for Snowflake
136+
match &parser.peek_token_ref().token {
137+
Token::SemiColon | Token::EOF => {
138+
return Some(Ok(Statement::StartTransaction {
139+
modes: Default::default(),
140+
begin: true,
141+
transaction: None,
142+
modifier: None,
143+
statements: vec![],
144+
exception: None,
145+
has_end_keyword: false,
146+
}))
147+
}
148+
_ => {
149+
// BEGIN ... [EXCEPTION] ... END block
150+
return Some(parser.parse_begin_exception_end());
151+
}
152+
}
136153
}
137154

138155
if parser.parse_keywords(&[Keyword::ALTER, Keyword::SESSION]) {

src/parser/mod.rs

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15597,25 +15597,6 @@ impl<'a> Parser<'a> {
1559715597
}
1559815598

1559915599
pub fn parse_begin_exception_end(&mut self) -> Result<Statement, ParserError> {
15600-
// Snowflake allows BEGIN as a standalone transaction statement (no END).
15601-
// If the next token is a semicolon or EOF, treat it as a standalone BEGIN.
15602-
if dialect_of!(self is SnowflakeDialect) {
15603-
match &self.peek_token_ref().token {
15604-
Token::SemiColon | Token::EOF => {
15605-
return Ok(Statement::StartTransaction {
15606-
begin: true,
15607-
statements: vec![],
15608-
exception: None,
15609-
has_end_keyword: false,
15610-
transaction: None,
15611-
modifier: None,
15612-
modes: Default::default(),
15613-
})
15614-
}
15615-
_ => {}
15616-
}
15617-
}
15618-
1561915600
let statements = self.parse_statement_list(&[Keyword::EXCEPTION, Keyword::END])?;
1562015601

1562115602
let exception = if self.parse_keyword(Keyword::EXCEPTION) {
@@ -15647,30 +15628,16 @@ impl<'a> Parser<'a> {
1564715628
None
1564815629
};
1564915630

15650-
if dialect_of!(self is SnowflakeDialect) {
15651-
// Make END optional for Snowflake. If present, set flag accordingly.
15652-
let has_end = self.parse_keyword(Keyword::END);
15653-
Ok(Statement::StartTransaction {
15654-
begin: true,
15655-
statements,
15656-
exception,
15657-
has_end_keyword: has_end,
15658-
transaction: None,
15659-
modifier: None,
15660-
modes: Default::default(),
15661-
})
15662-
} else {
15663-
self.expect_keyword(Keyword::END)?;
15664-
Ok(Statement::StartTransaction {
15665-
begin: true,
15666-
statements,
15667-
exception,
15668-
has_end_keyword: true,
15669-
transaction: None,
15670-
modifier: None,
15671-
modes: Default::default(),
15672-
})
15673-
}
15631+
self.expect_keyword(Keyword::END)?;
15632+
Ok(Statement::StartTransaction {
15633+
begin: true,
15634+
statements,
15635+
exception,
15636+
has_end_keyword: true,
15637+
transaction: None,
15638+
modifier: None,
15639+
modes: Default::default(),
15640+
})
1567415641
}
1567515642

1567615643
pub fn parse_end(&mut self) -> Result<Statement, ParserError> {

0 commit comments

Comments
 (0)