Skip to content
%pip install duckdb-engine -q
from sqlalchemy import create_engine
engine = create_engine("duckdb:///datacamp.duckdb")
with engine.connect() as connection:
cursor = connection.exec_driver_sql("SELECT * FROM bank LIMIT 3")
print(cursor.fetchall())
from llama_index.core import SQLDatabase
sql_database = SQLDatabase(engine, include_tables=["bank"])
from llama_index.core.query_engine import NLSQLTableQueryEngine
query_engine = NLSQLTableQueryEngine(sql_database)
response = query_engine.query("Which is the longest running campaign?")
from IPython.display import Markdown, display
display(Markdown(response.response))
response = query_engine.query("Which type of job has the most housing loan?")
display(Markdown(response.response))
print(response.metadata)
engine.close()