Skip to content

Commit 3c45057

Browse files
committed
fix bug with quoted identifiers in ALTER SESSION SET
1 parent d5ceeb2 commit 3c45057

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sqlmesh/core/engine_adapter/snowflake.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,12 @@ def catalog_rewriter(node: exp.Expression) -> exp.Expression:
622622
return expression
623623

624624
def _to_sql(self, expression: exp.Expression, quote: bool = True, **kwargs: t.Any) -> str:
625+
# Snowflake doesn't accept quoted identifiers in ALTER SESSION SET statements
626+
# e.g., ALTER SESSION SET "TIMEZONE" = 'UTC' is invalid
627+
# We need to disable quoting for these statements
628+
if isinstance(expression, (exp.Set, exp.Alter)):
629+
quote = False
630+
625631
return super()._to_sql(
626632
expression=self._normalize_catalog(expression), quote=quote, **kwargs
627633
)

sqlmesh/core/renderer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,14 @@ def _expand(node: exp.Expression) -> exp.Expression:
419419

420420
@contextmanager
421421
def _normalize_and_quote(self, query: E) -> t.Iterator[E]:
422-
if self._normalize_identifiers:
422+
# Snowflake doesn't accept quoted identifiers in ALTER SESSION SET statements
423+
# e.g., ALTER SESSION SET "TIMEZONE" = 'UTC' is invalid
424+
# SQLGlot parses "ALTER SESSION SET" as exp.Alter, not exp.Set
425+
# We need to skip both normalization and quoting for these statements
426+
# because quote_identifiers() modifies the AST directly and quotes persist
427+
if self._dialect == "snowflake" and isinstance(query, (exp.Set, exp.Alter)):
428+
yield query
429+
elif self._normalize_identifiers:
423430
with d.normalize_and_quote(
424431
query, self._dialect, self._default_catalog, quote=self._quote_identifiers
425432
) as query:

0 commit comments

Comments
 (0)