8.41. SQLAlchemy Query Exists
Exist
8.41.1. Exists
>>> q = session.query(User).filter(User.name == 'fred')
>>> session.query(q.exists())
SELECT EXISTS (
SELECT 1 FROM users WHERE users.name = :name_1
) AS anon_1
>>> session.query(User.id).filter(q.exists()).scalar()
>>> from sqlalchemy import literal
>>> session.query(literal(True)).filter(q.exists()).scalar()