Skip to content

Commit

Permalink
fix(oracle): enable dropping temporary tables
Browse files Browse the repository at this point in the history
Oracle requires you to truncate temp tables before dropping them, missed
handling this in the sqlglot port.
  • Loading branch information
gforsyth authored and kszucs committed Feb 12, 2024
1 parent f1e3312 commit 1dffd5e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ibis/backends/oracle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,27 @@ def create_table(
name, schema=schema, source=self, namespace=ops.Namespace(database=database)
).to_expr()

def drop_table(
self,
name: str,
database: str | None = None,
schema: str | None = None,
force: bool = False,
) -> None:
table = sg.table(name, db=schema, catalog=database, quoted=self.compiler.quoted)

with self.begin() as bind:
# global temporary tables cannot be dropped without first truncating them
#
# https://stackoverflow.com/questions/32423397/force-oracle-drop-global-temp-table
#
# ignore DatabaseError exceptions because the table may not exist
# because it's already been deleted
with contextlib.suppress(oracledb.DatabaseError):
bind.execute(f"TRUNCATE TABLE {table.sql(self.name)}")

super().drop_table(name, database=database, schema=schema, force=force)

def _register_in_memory_table(self, op: ops.InMemoryTable) -> None:
schema = op.schema

Expand Down

0 comments on commit 1dffd5e

Please sign in to comment.