diff --git a/sqlglot/dialects/tsql.py b/sqlglot/dialects/tsql.py index 65002427c2..26424c8c27 100644 --- a/sqlglot/dialects/tsql.py +++ b/sqlglot/dialects/tsql.py @@ -1166,7 +1166,7 @@ def partition_sql(self, expression: exp.Partition) -> str: def alter_sql(self, expression: exp.Alter) -> str: action = seq_get(expression.args.get("actions") or [], 0) - if isinstance(action, exp.RenameTable): + if isinstance(action, exp.AlterRename): return f"EXEC sp_rename '{self.sql(expression.this)}', '{action.this.name}'" return super().alter_sql(expression) diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py index 77a067404b..f68b627b97 100644 --- a/sqlglot/expressions.py +++ b/sqlglot/expressions.py @@ -1697,7 +1697,7 @@ class RenameColumn(Expression): arg_types = {"this": True, "to": True, "exists": False} -class RenameTable(Expression): +class AlterRename(Expression): pass @@ -7795,7 +7795,7 @@ def rename_table( this=old_table, kind="TABLE", actions=[ - RenameTable(this=new_table), + AlterRename(this=new_table), ], ) diff --git a/sqlglot/generator.py b/sqlglot/generator.py index 38b7c6ddcb..cdd580afd0 100644 --- a/sqlglot/generator.py +++ b/sqlglot/generator.py @@ -3225,12 +3225,12 @@ def altersortkey_sql(self, expression: exp.AlterSortKey) -> str: expressions = f"({expressions})" if expressions else "" return f"ALTER{compound} SORTKEY {this or expressions}" - def renametable_sql(self, expression: exp.RenameTable) -> str: + def alterrename_sql(self, expression: exp.AlterRename) -> str: if not self.RENAME_TABLE_WITH_DB: # Remove db from tables expression = expression.transform( lambda n: exp.table_(n.this) if isinstance(n, exp.Table) else n - ).assert_is(exp.RenameTable) + ).assert_is(exp.AlterRename) this = self.sql(expression, "this") return f"RENAME TO {this}" diff --git a/sqlglot/parser.py b/sqlglot/parser.py index b69cfcb721..45d2cf2845 100644 --- a/sqlglot/parser.py +++ b/sqlglot/parser.py @@ -6764,7 +6764,7 @@ def _parse_alter_table_drop(self) -> t.List[exp.Expression]: self._retreat(index) return self._parse_csv(self._parse_drop_column) - def _parse_alter_table_rename(self) -> t.Optional[exp.RenameTable | exp.RenameColumn]: + def _parse_alter_table_rename(self) -> t.Optional[exp.AlterRename | exp.RenameColumn]: if self._match(TokenType.COLUMN): exists = self._parse_exists() old_column = self._parse_column() @@ -6777,7 +6777,7 @@ def _parse_alter_table_rename(self) -> t.Optional[exp.RenameTable | exp.RenameCo return self.expression(exp.RenameColumn, this=old_column, to=new_column, exists=exists) self._match_text_seq("TO") - return self.expression(exp.RenameTable, this=self._parse_table(schema=True)) + return self.expression(exp.AlterRename, this=self._parse_table(schema=True)) def _parse_alter_table_set(self) -> exp.AlterSet: alter_set = self.expression(exp.AlterSet)