Is there a way to make SQLAlchemy generate a query with a custom column that is a subquery that correlates with current row:
SELECT
tab1.id,
tab1.col1,
...,
(
SELECT count(1) FROM tab2
WHERE tab2.tab1_id = tab1.id
GROUP BY tab2.col1
) as cnt
FROM tab1
WHERE ...
LIMIT 100
using the ORM API?
session.query(Tab1, ?(subquery for additional column)?).filter(...).limit(100)
I'm using PostgreSQL 9.3 and old version of SQLAlchemy 0.9.8
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…