I\'m trying to use a label in a having clause with sqlalchemy, but I\'m having problems getting it working. I\'m trying something like this:
qry = db.session.que
Try any of the two versions below (not sure the second one works on MySQL though):
rstuff = (Foo.max_stuff - db.func.sum(Bar.stuff))
qry = (
db.session.query(
Foo.id,
Foo.name,
rstuff.label('rstuff')
)
.join(Bar)
.group_by(Foo.id)
# version-1: probably universal, but repeats the expression
.having(rstuff >= 3)
# version-2: might depend on the RMDBS engine
# .having(db.literal_column('rstuff') >= 3)
)