-
Notifications
You must be signed in to change notification settings - Fork 16.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SET search_path TO {self._schema} is executing by SQLDatabase for all databases except 'snowflake' and 'bigquery'. #7928
Comments
Answer generated by a 🤖 AnswerI understand that you're encountering an issue with the SQLDatabase class in LangChain when using Oracle as your database. The problem arises because the command To address this issue, I suggest modifying the SQLDatabase class to include a condition for Oracle, similar to how it's done for 'snowflake' and 'bigquery'. Here's how you can adjust the code: if self._schema is not None:
if self.dialect == "snowflake":
connection.exec_driver_sql(
f"ALTER SESSION SET search_path='{self._schema}'"
)
elif self.dialect == "bigquery":
connection.exec_driver_sql(f"SET @@dataset_id='{self._schema}'")
elif self.dialect == "oracle":
# Oracle specific command to set schema
connection.exec_driver_sql(f"ALTER SESSION SET CURRENT_SCHEMA = {self._schema}")
else:
connection.exec_driver_sql(f"SET search_path TO {self._schema}")
cursor = connection.execute(text(command)) In this revised code, I've added a condition for 'oracle' and used the Please note that this is one potential solution based on the information provided. If this doesn't work or if you encounter other issues, there might be other factors at play that we would need to consider. If you find this solution correct and believe this is a bug that could impact other users, I encourage you to make a pull request with this change. This would greatly benefit the LangChain community. If you're still experiencing this issue after trying this solution, it might be helpful to ensure you're using the latest version of LangChain, as updates often contain bug fixes and improvements. SourcesThis response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. |
I have pull the source BUT did not get the changes. |
I ran into the same issue using Trino as my sql engine. Trino does not support |
- **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 <[email protected]>
…angchain-ai#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:** langchain-ai#7928, - **Dependencies:** No dependencies, - **Tag maintainer:** @baskaryan, --------- Co-authored-by: Bagatur <[email protected]>
Hi, @mail2mhossain, I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you encountered an error related to the SET search_path command with Oracle databases, which is specific to PostgreSQL. There was a suggestion to use SCHEMA.TABLE in all SQL queries instead, and a potential solution was provided by modifying the SQLDatabase class to include a condition for Oracle and using the Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you! |
System Info
LangChain Version- 0.0.235, Windows, Python Version-3.9.16
As per below source code of SQLDatabase, before executing any sql query, connection.exec_driver_sql(f"SET search_path TO {self._schema}") is executed for all database except 'snowflake' and 'bigquery'.
if self._schema is not None:
if self.dialect == "snowflake":
connection.exec_driver_sql(
f"ALTER SESSION SET search_path='{self._schema}'"
)
elif self.dialect == "bigquery":
connection.exec_driver_sql(f"SET @@dataset_id='{self._schema}'")
else:
connection.exec_driver_sql(f"SET search_path TO {self._schema}")
cursor = connection.execute(text(command))
As per my knowledge, The SET search_path command is specific to PostgreSQL, not Oracle. This is why I am getting the following error.
sqlalchemy.exc.DatabaseError: (oracledb.exceptions.DatabaseError) ORA-00922: missing or invalid option
[SQL: SET search_path TO evr1]
(Background on this error at: https://sqlalche.me/e/20/4xp6)
Oracle does not recognize this command.
I think it is better to use SCHEMA.TABLE in all sql queries.
Who can help?
No response
Information
Related Components
Reproduction
oracle_connection_str = f"oracle+oracledb://{username}:{password}@{hostname}:{port}/?service_name={service_name}"
db = SQLDatabase.from_uri(
oracle_connection_str,
schema="evr1",
include_tables=[ ],
sample_rows_in_table_info=3,
)
llm = ChatOpenAI(model_name=GPT_MODEL, temperature=0, openai_api_key=OpenAI_API_KEY)
toolkit = SQLDatabaseToolkit(
db=db,
llm=llm,
)
agent_executor = create_sql_agent(
llm=llm,
toolkit=toolkit,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
return_intermediate_steps=True,
handle_parsing_errors=_handle_error,
verbose=True,
)
response = agent_executor(user_input)
Expected behavior
Should not execute SET search_path TO {self._schema} for Oracle
The text was updated successfully, but these errors were encountered: