Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#19290 closed Uncategorized (duplicate)

'exclude' on aggregations makes wrong SQL

Reported by: letscan@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4
Severity: Normal Keywords: aggregation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a query like this:

qs.annotate(num_a=Sum(field1), num_b=Sum(field2)).exclude(num_a=0, num_b=0)

the query returns fewer objects than expected. I have checked the SQL of the query and found it is wrong:

SELECT ......... HAVING (NOT SUM(field1)=0 AND NOT SUM(field2)=0) .......

while what I want is like (just as the documentation says):

SELECT ......... HAVING (NOT (SUM(field1)=0 AND SUM(field2)=0)) .......

Change History (2)

comment:1 by Aymeric Augustin, 11 years ago

Component: Database layer (models, ORM)ORM aggregation
Resolution: duplicate
Status: newclosed

This looks exactly like #14971 and #10060. Please reopen if it's a different issue. Thanks!

comment:2 by Anssi Kääriäinen, 11 years ago

Component: ORM aggregationDatabase layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top