Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sqlmesh/core/engine_adapter/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,12 @@ def catalog_rewriter(node: exp.Expression) -> exp.Expression:
return expression

def _to_sql(self, expression: exp.Expression, quote: bool = True, **kwargs: t.Any) -> str:
# Snowflake doesn't accept quoted identifiers in ALTER SESSION SET statements
# e.g., ALTER SESSION SET "TIMEZONE" = 'UTC' is invalid
# We need to disable quoting for these statements
if isinstance(expression, (exp.Set, exp.Alter)):
quote = False

return super()._to_sql(
expression=self._normalize_catalog(expression), quote=quote, **kwargs
)
Expand Down
9 changes: 8 additions & 1 deletion sqlmesh/core/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,14 @@ def _expand(node: exp.Expression) -> exp.Expression:

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