Skip to content

fix: use Snowflake dialect for sqlglot SQL parsing#173

Open
elipollak wants to merge 1 commit intoSnowflake-Labs:mainfrom
elipollak:fix/sqlglot-snowflake-dialect
Open

fix: use Snowflake dialect for sqlglot SQL parsing#173
elipollak wants to merge 1 commit intoSnowflake-Labs:mainfrom
elipollak:fix/sqlglot-snowflake-dialect

Conversation

@elipollak
Copy link

@elipollak elipollak commented Mar 9, 2026

Summary

get_statement_type() in query_manager/tools.py calls sqlglot.parse_one(sql_string) without specifying dialect="snowflake". This causes sqlglot to use its generic SQL parser, which fails on valid Snowflake-specific syntax:

When parsing fails, the statement is classified as Unknown, which is rejected unless users add Unknown: true to their permissions config — defeating the purpose of statement-type filtering.

Fix

One-line change: sqlglot.parse_one(sql_string, dialect="snowflake")

This was independently identified and fixed by @atvaccaro in the Notion fork: makenotion/snowflake-mcp@3d0192d, which also includes comprehensive test coverage for Snowflake-specific syntax parsing. Those tests would be a good addition here as well.

Verification

Adding the dialect parameter does not change classification of any standard statement types:

Statement Default dialect Snowflake dialect
SELECT Select Select
DROP TABLE Drop Drop
DELETE Delete Delete
INSERT Insert Insert
UPDATE Update Update
TRUNCATE TruncateTable TruncateTable
ALTER TABLE Alter Alter
CREATE TABLE Create Create
MERGE Merge Merge
GRANT Grant Grant
UNION Union Union
SELECT ... value:key Unknown Select
COPY INTO @stage Unknown Copy

Fixes #161

@elipollak elipollak force-pushed the fix/sqlglot-snowflake-dialect branch 2 times, most recently from 718bd35 to 12a93c7 Compare March 9, 2026 11:00
Without dialect="snowflake", sqlglot fails to parse valid Snowflake
syntax (colon-path notation like f.value:key, COPY INTO, etc.),
classifying those statements as "Unknown" instead of their actual type.

Fixes Snowflake-Labs#161
@bccolema
Copy link

bccolema commented Mar 12, 2026

Oooo, would this also separate SHOW out to its own setting option instead of bucketing it under command?!! If so, PLEASE APPROVE

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.

COPY statements incorrectly classified as "Unknown" instead of "Copy"

2 participants