-
Notifications
You must be signed in to change notification settings - Fork 1
SQLAlchemy 20260318
Paul Moeller edited this page Mar 17, 2026
·
2 revisions
with _session() as s:
query = (
sqlalchemy.select(
# <table> or <column>...
)
.join(
# <table>,
# <clause>...
)
# or a combine select/join
.select_from(
select.t.device.join(
# <table>,
# <clause>...
)
)
.where(
# <clause>...
)
.order_by(
# <column>...
)
)with _session() as s:
# the Sesion provides the Table metadata via "tables" or "t"
device = s.tables.device
# the table metadata (SQLAlchemy Table) provides column metadata via "c"
device_name = device.c.device_name
# construct a query
query = sqlalchemy.select(device).where(
# can be confusing: SQLAlchemy clauses override operators == < >
device.c.device_name == "OTR2",
device.c.device_type == "PROF",
)
# execute the query via the Session
for row in s.select(query):
# can access Row values by position or name
row[0]
row.device_name