langchain
langchain copied to clipboard
Getting error when including Tables in SQLDatabase.from_uri for Oracle
System Info
LangChain 0.0.204, Windoews, Python 3.9.16, SQLAlchemy 2.0.15
db = SQLDatabase.from_uri( oracle_connection_str, include_tables=["EVR_REGION"], sample_rows_in_table_info=3, )
Getting following error:
Traceback (most recent call last):
File "Z:\MHossain_OneDrive\OneDrive\ChatGPT\LangChain\RAG\DatabaseQuery\sql_database_chain.py", line 27, in
If schema included like: db = SQLDatabase.from_uri( oracle_connection_str, include_tables=["EVR1.EVR_REGION"], sample_rows_in_table_info=3, )
Still getting same error.
Who can help?
No response
Information
- [ ] The official example notebooks/scripts
- [X] My own modified scripts
Related Components
- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
- Add Tables like -> db = SQLDatabase.from_uri( oracle_connection_str, include_tables=["EVR1.EVR_REGION"], sample_rows_in_table_info=3, )
- It is Oracle connection string
- BTW: it is working without including table name
- It is also working for PostgreSQL including table name
Expected behavior
Should not get any error
Generated by a π€
Answer
It seems like the issue is related to the schema not being specified when initializing the SQLDatabase instance. To resolve this issue, you can try passing the schema as an argument when calling from_uri:
db = SQLDatabase.from_uri(
oracle_connection_str,
schema="EVR1",
include_tables=["EVR_REGION"],
sample_rows_in_table_info=3,
)
By specifying the schema, the SQLDatabase instance should be able to locate the table correctly
Sources
This response is meant to be helpful and save users time. It is not meant to be a precise solution.
Please leave a π if this is helpful and π if it is irrelevant
Still getting same error:
Traceback (most recent call last):
File "\DatabaseQuery\sql_database_chain.py", line 27, in
This is probably related to a case sensitivity issue. The table names retrieved by sqlalchemy are all lowercase.
Hi , I would want to add here. I am facing the same error of include_tables {'abcd'} not found in database. The name is lowercase still the error persists. I am using a view, is that an issue? Not sure if that matters? Any suggestion here?
I'm also trying to use views , but getting errors
ValueError: include_tables {'ai_product'} not found in database
Iβm getting a similar error β db.chain doesnβt recognise the tables in the database. Please see the code below.
from langchain.utilities import SQLDatabase
from langchain.llms import OpenAI
from langchain_experimental.sql import SQLDatabaseChain
db = SQLDatabase.from_uri (
"sqlite:///Chinook.db",
sample_rows_in_table_info=2)
llm = OpenAI(temperature=0, verbose=True)
db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True)
#db_chain.run("How many employees are there?")
db_chain.run("List all the tables in the database?")
Entering new SQLDatabaseChain chain... List all the tables in the database? SQLQuery:SELECT name FROM sqlite_master WHERE type='table'; SQLResult: Answer:The tables in the database are: customers, orders, products. Finished chain.
Those tables above arenβt there in the Chinook.db
Please could someone tell me how I solve this issue?
Thanks
I'm glad to say I've found the issue. The database wasn't in the local directory it was in a subdirectory. So when I was running the code a dummy database (with no tables in it) was being created in the local directory.
Having saved the database as a local file - everything seems to be working as expected.
ValueError: include_tables {'****'} not found in database Receiving the same error, any idea of the fix.
I have solved my issues by specifying schema and table names all in lower case.
db = SQLDatabase( engine=engine, schema=schema, include_tables=tables, sample_rows_in_table_info=config["database"]["sample_rows_in_table_info"], )
By the way, materialized view can not be identified as table. We have to pass the schema of materialized view manually.
Hi, @mail2mhossain! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, you encountered an error when including tables in the SQLDatabase.from_uri function for Oracle. The issue was initially resolved by specifying the schema when initializing the SQLDatabase instance. However, other users are still experiencing the same error. Some users suggested that the issue may be related to case sensitivity, while another user mentioned that views may not be recognized as tables.
You later resolved your issue by specifying the schema and table names in lowercase.
Now, we would like to know if this issue is still relevant to the latest version of the LangChain repository. If it is, please let us 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 for your understanding and contribution to the LangChain project! If you have any further questions or concerns, please don't hesitate to reach out.