Vladyslav Ushakov Vladyslav Ushakov - 2 months ago 20
Python Question

How to get length of query result SqlAlchemy

I have simple query using SqlAlchemy ORM:

query = DBsession.query(AssetsItem).filter_by(
AssetsItem.id > 10,
AssetsItem.country = 'England'
)


How can i get length of my query result. I want to know how much AssetsItem i would get by this query

Answer Source
query = DBsession.query(AssetsItem).filter_by(
AssetsItem.id > 10,
AssetsItem.country = 'England'
)
your_count = query.count()

Documentation