From 6bc08266e0c9ca7841bb322259e69a9c0dd6a08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Alem=C3=A1n=20Cueto?= <45770986+Tazc54@users.noreply.github.com> Date: Sun, 19 Nov 2023 19:35:27 -0600 Subject: [PATCH] Fix for oracle schema parsing stated on the issue #7928 (#13545) - **Description:** In this pull request, we address an issue related to assigning a schema to the SQLDatabase class when utilizing an Oracle database. The current implementation encounters a bug where, upon attempting to execute a query, the alter session parse is not appropriately defined for Oracle, leading to an error, - **Issue:** #7928, - **Dependencies:** No dependencies, - **Tag maintainer:** @baskaryan, --------- Co-authored-by: Bagatur --- libs/langchain/langchain/utilities/sql_database.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/langchain/langchain/utilities/sql_database.py b/libs/langchain/langchain/utilities/sql_database.py index e1f48c0ba4..b5b4aab6bc 100644 --- a/libs/langchain/langchain/utilities/sql_database.py +++ b/libs/langchain/langchain/utilities/sql_database.py @@ -402,6 +402,10 @@ class SQLDatabase: # but `duckdb_engine` seemed to struggle with all of them: # https://github.com/Mause/duckdb_engine/issues/796 connection.exec_driver_sql(f"SET search_path TO {self._schema}") + elif self.dialect == "oracle": + connection.exec_driver_sql( + f"ALTER SESSION SET CURRENT_SCHEMA = {self._schema}" + ) else: # postgresql and other compatible dialects connection.exec_driver_sql("SET search_path TO %s", (self._schema,)) cursor = connection.execute(text(command))