Fixing issue with MSSQL connection (#8040)

My team recently faced an issue while using MSSQL and passing a schema
name.

We noticed that "SET search_path TO {self.schema}" is being called for
us, which is not a valid ms-sql query, and is specific to postgresql
dialect.

We were able to run it locally after this fix.


---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
Mahip Soni 2023-07-25 04:15:40 +05:30 committed by GitHub
parent 76102971c0
commit 1f055775f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -383,7 +383,9 @@ class SQLDatabase:
) )
elif self.dialect == "bigquery": elif self.dialect == "bigquery":
connection.exec_driver_sql(f"SET @@dataset_id='{self._schema}'") connection.exec_driver_sql(f"SET @@dataset_id='{self._schema}'")
else: elif self.dialect == "mssql":
pass
else: # postgresql and compatible dialects
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: