diff options
Diffstat (limited to 'sqlglot/dialects/tsql.py')
-rw-r--r-- | sqlglot/dialects/tsql.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/sqlglot/dialects/tsql.py b/sqlglot/dialects/tsql.py index 0eb0906..131307f 100644 --- a/sqlglot/dialects/tsql.py +++ b/sqlglot/dialects/tsql.py @@ -395,6 +395,20 @@ class TSQL(Dialect): CONCAT_NULL_OUTPUTS_STRING = True + def _parse_projections(self) -> t.List[t.Optional[exp.Expression]]: + """ + T-SQL supports the syntax alias = expression in the SELECT's projection list, + so we transform all parsed Selects to convert their EQ projections into Aliases. + + See: https://learn.microsoft.com/en-us/sql/t-sql/queries/select-clause-transact-sql?view=sql-server-ver16#syntax + """ + return [ + exp.alias_(projection.expression, projection.this.this, copy=False) + if isinstance(projection, exp.EQ) and isinstance(projection.this, exp.Column) + else projection + for projection in super()._parse_projections() + ] + def _parse_commit_or_rollback(self) -> exp.Commit | exp.Rollback: """Applies to SQL Server and Azure SQL Database COMMIT [ { TRAN | TRANSACTION } @@ -625,11 +639,7 @@ class TSQL(Dialect): LIMIT_FETCH = "FETCH" - def createable_sql( - self, - expression: exp.Create, - locations: dict[exp.Properties.Location, list[exp.Property]], - ) -> str: + def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> str: sql = self.sql(expression, "this") properties = expression.args.get("properties") |