Skip to content

Commit

Permalink
fix(snowflake): reset to original schema when resetting the database
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Aug 3, 2023
1 parent 14cf8ac commit 32ff832
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ibis/backends/snowflake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,18 @@ def _get_temp_view_definition(

def create_database(self, name: str, force: bool = False) -> None:
current_database = self.current_database
current_schema = self.current_schema
name = self._quote(name)
if_not_exists = "IF NOT EXISTS " * force
with self.begin() as con:
con.exec_driver_sql(f"CREATE DATABASE {if_not_exists}{name}")
# Snowflake automatically switches to the new database after creating
# it per
# https://docs.snowflake.com/en/sql-reference/sql/create-database#general-usage-notes
# so we switch back to the original database
con.exec_driver_sql(f"USE DATABASE {self._quote(current_database)}")
# so we switch back to the original database and schema
con.exec_driver_sql(
f"USE SCHEMA {self._quote(current_database)}.{self._quote(current_schema)}"
)

def drop_database(self, name: str, force: bool = False) -> None:
current_database = self.current_database
Expand Down

0 comments on commit 32ff832

Please sign in to comment.