diff --git a/ibis/backends/mssql/__init__.py b/ibis/backends/mssql/__init__.py index e24c88faf846..350fc5279bff 100644 --- a/ibis/backends/mssql/__init__.py +++ b/ibis/backends/mssql/__init__.py @@ -726,7 +726,7 @@ def create_table( sge.Drop(kind="TABLE", this=this, exists=True).sql(self.dialect) ) old = raw_table.sql(self.dialect) - new = raw_this.sql(self.dialect) + new = raw_this.name cur.execute(f"EXEC sp_rename '{old}', '{new}'") if temp: diff --git a/ibis/backends/tests/test_client.py b/ibis/backends/tests/test_client.py index 3161c5a303dd..04a13b1dbf89 100644 --- a/ibis/backends/tests/test_client.py +++ b/ibis/backends/tests/test_client.py @@ -1855,6 +1855,21 @@ def test_table_not_found(con): con.table(gen_name("table_not_found")) +@pytest.mark.parametrize( + "overwrite", + [ + param( + True, + marks=[ + pytest.mark.notimpl( + ["mysql", "singlestoredb", "risingwave"], + reason="Cross-database load fails with overwrite (needs investigation).", + ) + ], + ), + False, + ], +) @pytest.mark.notimpl( ["flink"], raises=com.IbisError, reason="not yet implemented for Flink" ) @@ -1863,7 +1878,7 @@ def test_table_not_found(con): raises=AssertionError, reason="Schema resolution issue with cross-database table loading in Materialize (needs investigation).", ) -def test_no_accidental_cross_database_table_load(con_create_database): +def test_no_accidental_cross_database_table_load(con_create_database, overwrite): con = con_create_database # Create an extra database @@ -1874,7 +1889,9 @@ def test_no_accidental_cross_database_table_load(con_create_database): table := gen_name("table"), schema=(sch1 := ibis.schema({"a": "int"})) ) - con.create_table(table, schema=ibis.schema({"b": "string"}), database=dbname) + con.create_table( + table, schema=ibis.schema({"b": "string"}), database=dbname, overwrite=overwrite + ) # Can grab table object from current db: t = con.table(table)