Skip to content

Commit

Permalink
fix(duckdb,clickhouse): fix create_table() in database files with spa…
Browse files Browse the repository at this point in the history
…ces in the name

If you tried

```python
import ibis

conn = ibis.duckdb.connect("with space.duckdb")
conn.create_table("foo", {"a": [0,1,2]})
```

then you would get the DDL `CREATE TABLE with space.main."foo" ("a" BIGINT)`. Now, the database name is quoted.
  • Loading branch information
NickCrews committed Aug 11, 2024
1 parent 9165255 commit 630e4c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def create_table(
schema = obj.schema()

this = sge.Schema(
this=sg.table(name, db=database),
this=sg.table(name, db=database, quoted=self.compiler.quoted),
expressions=[
sge.ColumnDef(
this=sg.to_identifier(name, quoted=self.compiler.quoted),
Expand Down
12 changes: 4 additions & 8 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@ def create_table(
else:
temp_name = name

initial_table = sge.Table(
this=sg.to_identifier(temp_name, quoted=self.compiler.quoted),
catalog=catalog,
db=database,
initial_table = sg.table(
temp_name, catalog=catalog, db=database, quoted=self.compiler.quoted
)
target = sge.Schema(this=initial_table, expressions=column_defs)

Expand All @@ -201,10 +199,8 @@ def create_table(
)

# This is the same table as initial_table unless overwrite == True
final_table = sge.Table(
this=sg.to_identifier(name, quoted=self.compiler.quoted),
catalog=catalog,
db=database,
final_table = sg.table(
name, catalog=catalog, db=database, quoted=self.compiler.quoted
)
with self._safe_raw_sql(create_stmt) as cur:
if query is not None:
Expand Down

0 comments on commit 630e4c0

Please sign in to comment.