Re: Annotation failure (Combining multiple aggregations)

2015-12-15 Thread Anssi Kääriäinen
On Tuesday, December 8, 2015 at 9:19:52 AM UTC+2, Anssi Kääriäinen wrote: > > On Friday, December 4, 2015 at 5:47:43 PM UTC+2, Paulo Maciel wrote: >> >> Combining multiple aggregations with annotate() will yield the wrong >> results , as multiple >> ta

Re: Annotation failure (Combining multiple aggregations)

2015-12-09 Thread Michael
On Wednesday, December 9, 2015 at 1:02:13 AM UTC-6, Anssi Kääriäinen wrote: > > This one actually does work with filter(). As the count is inside a > subselect, it can be used directly in the WHERE clause without GROUP BY or > HAVING. Using a direct count without a subselect wouldn't work. > Ha,

Re: Annotation failure (Combining multiple aggregations)

2015-12-08 Thread Anssi Kääriäinen
On Tuesday, December 8, 2015 at 5:28:08 PM UTC+2, Michael wrote: > > On Tuesday, December 8, 2015 at 1:26:52 AM UTC-6, Anssi Kääriäinen wrote: >> >> >> Come to think of it, we already have a workaround: >>Book.objects.annotate(author_cnt=RawSQL("(select count(*) from author >> where author.boo

Re: Annotation failure (Combining multiple aggregations)

2015-12-08 Thread Anssi Kääriäinen
On Tuesday, December 8, 2015 at 2:52:07 PM UTC+2, Josh Smeaton wrote: > > Yeah I'm wary that a lot of the problems with extra() will be replicated > by users switching to RawSQL() instead. It won't handle realiasing or group > by correctly. > The group by case we can fix by creating a separate R

Re: Annotation failure (Combining multiple aggregations)

2015-12-08 Thread Michael
On Tuesday, December 8, 2015 at 1:26:52 AM UTC-6, Anssi Kääriäinen wrote: > > > Come to think of it, we already have a workaround: >Book.objects.annotate(author_cnt=RawSQL("(select count(*) from author > where author.book_id = book.book_id)"). > Yes, you can do a subquery to get the Sum or Co

Re: Annotation failure (Combining multiple aggregations)

2015-12-08 Thread Josh Smeaton
Yeah I'm wary that a lot of the problems with extra() will be replicated by users switching to RawSQL() instead. It won't handle realiasing or group by correctly. On Tuesday, 8 December 2015 18:26:52 UTC+11, Anssi Kääriäinen wrote: > > > > On Tuesday, December 8, 2015 at 3:16:20 AM UTC+2, Michae

Re: Annotation failure (Combining multiple aggregations)

2015-12-07 Thread Anssi Kääriäinen
On Tuesday, December 8, 2015 at 3:16:20 AM UTC+2, Michael wrote: > > I have the same problem. > > I tried to use `extra` but then I can't filter so it's not the best. > > Anybody has more info or a workaround? > Come to think of it, we already have a workaround: Book.objects.annotate(author_c

Re: Annotation failure (Combining multiple aggregations)

2015-12-07 Thread Anssi Kääriäinen
On Friday, December 4, 2015 at 5:47:43 PM UTC+2, Paulo Maciel wrote: > > Combining multiple aggregations with annotate() will yield the wrong > results , as multiple tables > are cross joined. Due to the use of LEFT OUTER JOIN, duplicate records > wil

Re: Annotation failure (Combining multiple aggregations)

2015-12-07 Thread Michael
I have the same problem. I tried to use `extra` but then I can't filter so it's not the best. Anybody has more info or a workaround? Thanks On Friday, December 4, 2015 at 9:47:43 AM UTC-6, Paulo Maciel wrote: > > Combining multiple aggregations with annotate() will yield the wrong > results <

Annotation failure (Combining multiple aggregations)

2015-12-04 Thread Paulo Maciel
Combining multiple aggregations with annotate() will yield the wrong results , as multiple tables are cross joined. Due to the use of LEFT OUTER JOIN, duplicate records will be generated if some of the joined tables contain more records than the other