diff --git a/ibis/backends/mssql/__init__.py b/ibis/backends/mssql/__init__.py index 32ab15166a56..2582476b18b7 100644 --- a/ibis/backends/mssql/__init__.py +++ b/ibis/backends/mssql/__init__.py @@ -602,7 +602,7 @@ def create_table( *, schema: sch.SchemaLike | None = None, database: str | None = None, - temp: bool = False, + temp: bool | None = None, overwrite: bool = False, ) -> ir.Table: """Create a new table. @@ -682,7 +682,7 @@ def create_table( raw_table = sg.table(temp_name, catalog=catalog, db=db, quoted=False) target = sge.Schema( this=sg.table( - "#" * temp + temp_name, catalog=catalog, db=db, quoted=quoted + "#" * bool(temp) + temp_name, catalog=catalog, db=db, quoted=quoted ), expressions=schema.to_sqlglot(self.dialect), ) @@ -701,7 +701,7 @@ def create_table( # for the subsequent `Insert`, so we need to shove a `#` in # front of the table identifier. _table = sg.table( - "##" * temp + temp_name, + "##" * bool(temp) + temp_name, catalog=catalog, db=db, quoted=self.compiler.quoted, diff --git a/ibis/backends/mssql/tests/test_client.py b/ibis/backends/mssql/tests/test_client.py index 3a72a75746c1..6850f489852c 100644 --- a/ibis/backends/mssql/tests/test_client.py +++ b/ibis/backends/mssql/tests/test_client.py @@ -18,6 +18,8 @@ MSSQL_PYODBC_DRIVER, MSSQL_USER, ) +from ibis.backends.tests.errors import PyODBCProgrammingError +from ibis.util import gen_name RAW_DB_TYPES = [ # Exact numbers @@ -259,3 +261,36 @@ def test_dot_sql_with_unnamed_columns(con): df = expr.execute() assert len(df) == 1 + + +@pytest.mark.parametrize( + "temp", + [ + param( + True, + marks=pytest.mark.xfail( + raises=PyODBCProgrammingError, + reason="dropping temp tables isn't implemented", + ), + ), + False, + None, + ], + ids=[ + "temp", + "no-temp", + "no-temp-none", + ], +) +def test_create_temp_table(con, temp): + t = con.create_table( + name := gen_name("mssql_delete_me"), + schema={"a": "int"}, + temp=temp, + ) + try: + assert int(t.count().execute()) == 0 + assert t.schema() == ibis.schema({"a": "int"}) + assert t.columns == ("a",) + finally: + con.drop_table(name)