langchain
langchain copied to clipboard
psycopg2.errors.AmbiguousColumn exception when using SQLDatabaseChain
System Info
Langchain Version: 0.0.175 Platform: macos Python version: 3.9 Database: Postgres
Who can help?
@vowelparrot @agola11
Information
- [X] The official example notebooks/scripts
- [ ] 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
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
Steps to reproduce:
- Let's say we have two tables
users
&profiles
and they are both have a column namedtags
. - SQLDatabaseChain produce the following query:
SELECT "first_name", "last_name", "tags" FROM users INNER JOIN profiles ON users.id=profiles.user_id
- This generates the following exception:
ProgrammingError('(psycopg2.errors.AmbiguousColumn) column reference "tags" is ambiguous LINE 1: SELECT "first_name", "last_name", "tags")
Expected behavior
I would expect it to produce the query with table name specified, at least for the columns who share the same name across these these two tables.
I've tried to add enable use_query_checker but it didn't help. I also tried to add to the QUERY_CHECKER
the following line:
- Adding the table name when referencing columns that are specified in multiple tables (i.e. ambiguous column names)
- it didn't help either