Skip to content

Commit f15c92a

Browse files
Snowflake: BEGIN <txn-keyword> := … is a scripting assignment, not a named transaction
When BEGIN is followed by TRANSACTION/WORK/NAME and the next token is := the block is a scripting assignment to a variable with that name, so keep it on the BEGIN…END scripting path instead of routing to parse_begin().
1 parent 2008030 commit f15c92a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/dialect/snowflake.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,15 @@ impl Dialect for SnowflakeDialect {
262262
if parser.parse_keyword(Keyword::BEGIN) {
263263
// Snowflake supports both `BEGIN TRANSACTION` and `BEGIN ... END` blocks.
264264
// If the next keyword indicates a transaction statement, let the
265-
// standard parse_begin() handle it.
266-
if parser
265+
// standard parse_begin() handle it. `BEGIN <kw> := …`, however, is a
266+
// scripting block assigning to a variable that happens to be named
267+
// after a transaction keyword — an immediately following `:=` keeps
268+
// the block on the scripting path.
269+
let begins_transaction = parser
267270
.peek_one_of_keywords(&[Keyword::TRANSACTION, Keyword::WORK, Keyword::NAME])
268271
.is_some()
272+
&& parser.peek_nth_token_ref(1).token != Token::Assignment;
273+
if begins_transaction
269274
|| matches!(parser.peek_token_ref().token, Token::SemiColon | Token::EOF)
270275
{
271276
parser.prev_token();

0 commit comments

Comments
 (0)