Fix for syntax when setting search_path for Snowflake database (#4747)

# Fixes syntax for setting Snowflake database search_path

An error occurs when using a Snowflake database and providing a schema
argument.
I have updated the syntax to run a Snowflake specific query when the
database dialect is 'snowflake'.
This commit is contained in:
Aidan Boland 2023-05-19 04:30:38 +01:00 committed by GitHub
parent db6f7ed0ba
commit c06973261a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -224,6 +224,11 @@ class SQLDatabase:
""" """
with self._engine.begin() as connection: with self._engine.begin() as connection:
if self._schema is not None: if self._schema is not None:
if self.dialect == "snowflake":
connection.exec_driver_sql(
f"ALTER SESSION SET search_path='{self._schema}'"
)
else:
connection.exec_driver_sql(f"SET search_path TO {self._schema}") connection.exec_driver_sql(f"SET search_path TO {self._schema}")
cursor = connection.execute(text(command)) cursor = connection.execute(text(command))
if cursor.returns_rows: if cursor.returns_rows: