Skip to content

Commit 0796ed2

Browse files
authored
fix(mssql): use one-part name in sp_rename when creating a table with override=true
The `sp_rename` stored proc requires that the new name is just the table name. Previously we were supplying the fully qualified name and this was causing incorrect tables to be created. For example, `conn.create_table("my_table", database=("my_db", "dbo"), override=true)' would create a table called `my_db.dbo.[my_db.dbo.my_table]` Ref: https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-rename-transact-sql
1 parent 1de88cb commit 0796ed2

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

ibis/backends/mssql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def create_table(
726726
sge.Drop(kind="TABLE", this=this, exists=True).sql(self.dialect)
727727
)
728728
old = raw_table.sql(self.dialect)
729-
new = raw_this.sql(self.dialect)
729+
new = raw_this.name
730730
cur.execute(f"EXEC sp_rename '{old}', '{new}'")
731731

732732
if temp:

0 commit comments

Comments
 (0)