From b64a443f72c3a978533fbf0c614ddbd4911b26f4 Mon Sep 17 00:00:00 2001 From: cccs-eric Date: Wed, 6 Sep 2023 19:19:37 -0400 Subject: [PATCH] Fix SQL search_path for Trino query engine (#10248) This PR replaces the generic `SET search_path TO` statement by `USE` for the Trino dialect since Trino does not support `SET search_path`. Official Trino documentation can be found [here](https://trino.io/docs/current/sql/use.html). With this fix, the `SQLdatabase` will now be able to set the current schema and execute queries using the Trino engine. It will use the catalog set as default by the connection uri. --- libs/langchain/langchain/utilities/sql_database.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/langchain/langchain/utilities/sql_database.py b/libs/langchain/langchain/utilities/sql_database.py index 110f081d3c..e621ffd17b 100644 --- a/libs/langchain/langchain/utilities/sql_database.py +++ b/libs/langchain/langchain/utilities/sql_database.py @@ -384,6 +384,8 @@ class SQLDatabase: connection.exec_driver_sql(f"SET @@dataset_id='{self._schema}'") elif self.dialect == "mssql": pass + elif self.dialect == "trino": + connection.exec_driver_sql(f"USE {self._schema}") else: # postgresql and compatible dialects connection.exec_driver_sql(f"SET search_path TO {self._schema}") cursor = connection.execute(text(command))