Skip to content

Commit

Permalink
fix(oracle): allow passing both overwrite and temp to create_table
Browse files Browse the repository at this point in the history
  • Loading branch information
gforsyth authored and kszucs committed Feb 12, 2024
1 parent dc34f61 commit 3ce4766
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ibis/backends/oracle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,27 +311,32 @@ def create_table(
else:
temp_name = name

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

create_stmt = sge.Create(
kind="TABLE",
this=target,
properties=sge.Properties(expressions=properties),
)

this = sg.table(name, catalog=database, quoted=self.compiler.quoted)
# This is the same table as initial_table unless overwrite == True
final_table = sg.table(name, catalog=database, quoted=self.compiler.quoted)
with self._safe_raw_sql(create_stmt) as cur:
if query is not None:
insert_stmt = sge.Insert(this=table, expression=query).sql(self.name)
insert_stmt = sge.Insert(this=initial_table, expression=query).sql(
self.name
)
cur.execute(insert_stmt)

if overwrite:
cur.execute(
sge.Drop(kind="TABLE", this=this, exists=True).sql(self.name)
self.drop_table(
final_table.name, final_table.catalog, final_table.db, force=True
)
cur.execute(
f"ALTER TABLE IF EXISTS {table.sql(self.name)} RENAME TO {this.sql(self.name)}"
f"ALTER TABLE IF EXISTS {initial_table.sql(self.name)} RENAME TO {final_table.sql(self.name)}"
)

if schema is None:
Expand Down Expand Up @@ -370,7 +375,7 @@ def _register_in_memory_table(self, op: ops.InMemoryTable) -> None:
if (name := op.name) not in self.list_tables():
quoted = self.compiler.quoted
column_defs = [
sg.exp.ColumnDef(
sge.ColumnDef(
this=sg.to_identifier(colname, quoted=quoted),
kind=self.compiler.type_mapper.from_ibis(typ),
constraints=(
Expand Down

0 comments on commit 3ce4766

Please sign in to comment.