langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Getting error when including Tables in SQLDatabase.from_uri for Oracle

Open mail2mhossain opened this issue 2 years ago β€’ 4 comments

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 db = SQLDatabase.from_uri( File "Z:\Users\User\anaconda3\envs\hugging_face_env\lib\site-packages\langchain\sql_database.py", line 124, in from_uri return cls(create_engine(database_uri, **_engine_args), **kwargs) File "Z:\Users\User\anaconda3\envs\hugging_face_env\lib\site-packages\langchain\sql_database.py", line 73, in init raise ValueError( ValueError: include_tables {'EVR_REGION'} not found in database

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

  1. Add Tables like -> db = SQLDatabase.from_uri( oracle_connection_str, include_tables=["EVR1.EVR_REGION"], sample_rows_in_table_info=3, )
  2. It is Oracle connection string
  3. BTW: it is working without including table name
  4. It is also working for PostgreSQL including table name

Expected behavior

Should not get any error

mail2mhossain avatar Jun 19 '23 07:06 mail2mhossain

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

devstein avatar Jun 20 '23 00:06 devstein

Still getting same error: Traceback (most recent call last): File "\DatabaseQuery\sql_database_chain.py", line 27, in db = SQLDatabase.from_uri( File "\envs\hugging_face_env\lib\site-packages\langchain\sql_database.py", line 124, in from_uri return cls(create_engine(database_uri, **_engine_args), **kwargs) File "\envs\hugging_face_env\lib\site-packages\langchain\sql_database.py", line 73, in init raise ValueError( ValueError: include_tables {'EVR_REGION'} not found in database

mail2mhossain avatar Jun 20 '23 02:06 mail2mhossain

This is probably related to a case sensitivity issue. The table names retrieved by sqlalchemy are all lowercase.

tschager avatar Jul 03 '23 11:07 tschager

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?

Rajlakshmi0187 avatar Jul 07 '23 08:07 Rajlakshmi0187

I'm also trying to use views , but getting errors

ValueError: include_tables {'ai_product'} not found in database

doit-ceo avatar Jul 30 '23 16:07 doit-ceo

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

fmleigh avatar Aug 23 '23 08:08 fmleigh

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.

fmleigh avatar Aug 23 '23 10:08 fmleigh

ValueError: include_tables {'****'} not found in database Receiving the same error, any idea of the fix.

mkalidas avatar Aug 29 '23 14:08 mkalidas

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.

mail2mhossain avatar Aug 30 '23 02:08 mail2mhossain

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.

dosubot[bot] avatar Nov 29 '23 16:11 dosubot[bot]