Skip to content

Conversation

@guan404ming
Copy link
Member

@guan404ming guan404ming commented Jan 30, 2026

Why

I'm currently building sql-parser npm pkg for js/ts named sqlparser-ts, which powered by this amazing repo via WebAssembly! When reconstruct all dialects test in typescript, I find some issue and decide to contribute back to upstream~

The MSSQL dialect previously had no way to parse standalone BEGIN...END blocks.
BEGIN SELECT 1; END would fail because parse_begin() only handles BEGIN TRANSACTION.

How

wires MSSQL into the same path like BigQuery and Snowflake

Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com>
Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com>
Comment on lines +148 to +162
if parser.parse_keyword(Keyword::BEGIN) {
if parser.peek_keyword(Keyword::TRANSACTION)
|| parser.peek_keyword(Keyword::WORK)
|| parser.peek_keyword(Keyword::TRY)
|| parser.peek_keyword(Keyword::CATCH)
|| parser.peek_keyword(Keyword::DEFERRED)
|| parser.peek_keyword(Keyword::IMMEDIATE)
|| parser.peek_keyword(Keyword::EXCLUSIVE)
|| parser.peek_token_ref().token == Token::SemiColon
|| parser.peek_token_ref().token == Token::EOF
{
parser.prev_token();
return None;
}
Some(parser.parse_begin_exception_end())
Copy link
Contributor

Choose a reason for hiding this comment

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

would a condition like this do what we want?

if parse.peek_keywords(BEGIN, TRANSACTION) {
    None
} else if parse_keyword(BEGIN) {
    Some(parser.parse_begin_exception_end())
}

its not super clear to me why the current logic looks at WORK, TRY etc keywords?

Copy link
Member Author

@guan404ming guan404ming Jan 31, 2026

Choose a reason for hiding this comment

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

Thanks for the review. These keywords are checked because parse_begin() handles more than just BEGIN TRANSACTION. It also handles WORK, TRY, CATCH, DEFERRED, IMMEDIATE, EXCLUSIVE (since MsSql's supports_start_transaction_modifier() returns true), as well as bare BEGIN;. If any of these are missed, they'd be incorrectly routed to parse_begin_exception_end() and fail to parse.

For example, BEGIN TRY ... END TRY is valid MSSQL syntax. If we only check for BEGIN TRANSACTION, then BEGIN TRY would fall through to parse_begin_exception_end(), which would try to parse TRY as a SQL statement and fail. because TRY is supposed to be handled as a

} else if self.parse_keyword(Keyword::TRY) {
Some(TransactionModifier::Try)

Copy link
Member Author

Choose a reason for hiding this comment

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

Feel free to let me know if there are any not clear, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants