langchain icon indicating copy to clipboard operation
langchain copied to clipboard

fix sqlite internal tables breaking table_info

Open jzluo opened this issue 2 years ago • 0 comments

With the current method used to get the SQL table info, sqlite internal schema tables are being included and are not being handled correctly by sqlalchemy because the columns have no types. This is easy to see with the Chinook database:

db = SQLDatabase.from_uri("sqlite:///Chinook.db")
print(db.table_info)
...
sqlalchemy.exc.CompileError: (in table 'sqlite_sequence', column 'name'): Can't generate DDL for NullType(); did you forget to specify a type on this Column?

SQLAlchemy 2.0 ignores these by default: https://github.com/sqlalchemy/sqlalchemy/blob/63d90b0f44016b15bed6c4108d90a71c15f05a09/lib/sqlalchemy/dialects/sqlite/base.py#L2096-L2123

jzluo avatar Feb 22 '23 03:02 jzluo