q.group_by().having().count() creates an extra HAVING
Issue #2130
resolved
Specific example:
# This is fine:
q = session.query(Foo).group_by(Foo.col2).having(func.count(Foo.col2) > 0)
# This creates an extra HAVING:
q.count()
Resulting SQL:
SELECT count(1) AS count_1 FROM (
SELECT t.col1 AS t_col1, t.col2 AS t_col2 FROM t GROUP BY t.col2 HAVING count(t.col2) > ?
) AS anon_1 HAVING count(t.col2) > ?
Resulting error:
sqlalchemy.exc.OperationalError: (OperationalError) a GROUP BY clause is required before HAVING u'SELECT count(1) AS count_1 \nFROM (SELECT t.col1 AS t_col1, t.col2 AS t_col2 \nFROM t GROUP BY t.col2 \nHAVING count(t.col2) > ?) AS anon_1 \nHAVING count(t.col2) > ?' (0, 0)
Comments (4)
-
Account Deleted -
repo owner - changed milestone to 0.6.7
oh no that's 0.6.7 too, just do:
print q.from_self()
count uses from_self() in 0.7.
-
repo owner - changed status to resolved
-
repo owner - removed milestone
Removing milestone: 0.6.7 (automated comment)
- Log in to comment
By the way, this bug is only present in 0.7, works fine in 0.6.5.