Skip to content

Commit ea1c179

Browse files
authored
fix(mssql): allow temp=None (#10289)
1 parent 7d98330 commit ea1c179

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

ibis/backends/mssql/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def create_table(
602602
*,
603603
schema: sch.SchemaLike | None = None,
604604
database: str | None = None,
605-
temp: bool = False,
605+
temp: bool | None = None,
606606
overwrite: bool = False,
607607
) -> ir.Table:
608608
"""Create a new table.
@@ -682,7 +682,7 @@ def create_table(
682682
raw_table = sg.table(temp_name, catalog=catalog, db=db, quoted=False)
683683
target = sge.Schema(
684684
this=sg.table(
685-
"#" * temp + temp_name, catalog=catalog, db=db, quoted=quoted
685+
"#" * bool(temp) + temp_name, catalog=catalog, db=db, quoted=quoted
686686
),
687687
expressions=schema.to_sqlglot(self.dialect),
688688
)
@@ -701,7 +701,7 @@ def create_table(
701701
# for the subsequent `Insert`, so we need to shove a `#` in
702702
# front of the table identifier.
703703
_table = sg.table(
704-
"##" * temp + temp_name,
704+
"##" * bool(temp) + temp_name,
705705
catalog=catalog,
706706
db=db,
707707
quoted=self.compiler.quoted,

ibis/backends/mssql/tests/test_client.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
MSSQL_PYODBC_DRIVER,
1919
MSSQL_USER,
2020
)
21+
from ibis.backends.tests.errors import PyODBCProgrammingError
22+
from ibis.util import gen_name
2123

2224
RAW_DB_TYPES = [
2325
# Exact numbers
@@ -259,3 +261,36 @@ def test_dot_sql_with_unnamed_columns(con):
259261

260262
df = expr.execute()
261263
assert len(df) == 1
264+
265+
266+
@pytest.mark.parametrize(
267+
"temp",
268+
[
269+
param(
270+
True,
271+
marks=pytest.mark.xfail(
272+
raises=PyODBCProgrammingError,
273+
reason="dropping temp tables isn't implemented",
274+
),
275+
),
276+
False,
277+
None,
278+
],
279+
ids=[
280+
"temp",
281+
"no-temp",
282+
"no-temp-none",
283+
],
284+
)
285+
def test_create_temp_table(con, temp):
286+
t = con.create_table(
287+
name := gen_name("mssql_delete_me"),
288+
schema={"a": "int"},
289+
temp=temp,
290+
)
291+
try:
292+
assert int(t.count().execute()) == 0
293+
assert t.schema() == ibis.schema({"a": "int"})
294+
assert t.columns == ("a",)
295+
finally:
296+
con.drop_table(name)

0 commit comments

Comments
 (0)