Using COUNT(*) OVER() in current query with SQLAlchemy over PostgreSQL

via https://stackoverflow.com/a/5215028

So I could not find any examples in the SQLAlchemy documentation, but I found these functions:

And I managed to combine them to produce exactly the result I was looking for:

from sqlalchemy import func
query = session.query(Guest, func.count(Guest.id).over().label('total'))
query = query.filter(Guest.deleted == None)
query = query.order_by(Guest.id.asc())
query = query.offset(0)
query = query.limit(50)
result = query.all()

Cheers!

P.S. I also found this question on Stack Overflow, which was unanswered.

# NOTE: I am not responsible for any expired content.
[email protected]:56:17+08:00
[email protected]:56:31+08:00
[email protected]://github.com/ferstar/blog/issues/37
加载评论