Hacker News new | ask | show | jobs
by spthorn60 2912 days ago
But he has a valid point in HAVING not being able to reference an aggregate column by the AS name in the SELECT.
1 comments

Yeah, I always considered that quite strange, given the order of the query (and even though forward references are found almost everywhere in SQL, making it even more strange)

ORM-wise it's not a huge issue, I tend to move them outside the query definition to avoid the duplication. E.g.

    comment_count = func.count(Comment.id).label('comment_count')
    query = (session.query(User, comment_count)
             .join(User.comments)
             .group_by(User)
             .having(comment_count > 10))