From 32ff8329e8905727772956875776f264e8fbe1d6 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:22:24 -0400 Subject: [PATCH] fix(snowflake): reset to original schema when resetting the database --- ibis/backends/snowflake/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ibis/backends/snowflake/__init__.py b/ibis/backends/snowflake/__init__.py index a749db306eed..858e7d619741 100644 --- a/ibis/backends/snowflake/__init__.py +++ b/ibis/backends/snowflake/__init__.py @@ -507,6 +507,7 @@ 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: @@ -514,8 +515,10 @@ def create_database(self, name: str, force: bool = False) -> None: # 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