SQLAlchemy has two parts:
* ORM: this maps table and relationships between tables to Python objects
* Core: alows you to write and execute SQL using Python exspressions
Select statment:
import pandas as pd
from sqlalchemy import select, cast, column, create_engine, Table, MetaData, insert
engine = create_engine("...")
metadata = MetaData(bind=engine, reflect=True)
table_X = metadata.tables['table_X']
sql = select([ # Dont use table_X.select() ass you cant specify columns
table_X.columns('x')
]
).limit(10)
pd.read_sql_query(sql, engine)
To inspect an SQL statment:
str(sql) or print(sql)
To compile against SQL variant and include paramters:
print(select_i.compile(eng, compile_kwargs={"literal_binds": True}))
Other cheet sheet: https://www.pythonsheets.com/notes/python-sqlalchemy.html