Skip to content

Commit

Permalink
Fix SQL search_path for Trino query engine (#10248)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cccs-eric authored Sep 6, 2023
1 parent 1fb7bdd commit b64a443
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/langchain/langchain/utilities/sql_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ def _execute(self, command: str, fetch: Optional[str] = "all") -> Sequence:
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))
Expand Down

0 comments on commit b64a443

Please sign in to comment.