I've seen *extra()* misused in cases where developers came from a background of writing raw SQL and then used it rather than figuring out the (often relatively simple) ORM way of doing it. This is then a big maintenance burden, and the harsher warning against its use is a good idea.
Also thanks for documenting *RawSQL*, didn't realize it was usable until now so I've been able to get rid of some *extra()* usage in django-mysql. On Wednesday, August 5, 2015 at 1:09:30 AM UTC+1, Josh Smeaton wrote: > > You're right about that. You can aggregate over custom expressions. For > aggregating over enums you should be able to use case expressions > > On Wed, 5 Aug 2015 at 05:05 Anssi Kääriäinen <akaa...@gmail.com > <javascript:>> wrote: > >> On Tuesday, August 4, 2015, Shai Berger <sh...@platonix.com <javascript:>> >> wrote: >>> >>> The classic database aggregation examples involve aggregation over time: >>> Sum >>> of sales per quarter (which is, itself, a function over date); average >>> temparature per month; etc. All these require group-by clauses which name >>> (expressions over) columns which are not FKs. >>> >>> >> The following should work: >> >> >> >> qs.annotate(quarter=Quarter('sold_date')).values('quarter').annotate(sum=Sum('amount')) >> >> I recall some changes to how the group by expression is generated for >> expressions. If I recall correctly the group by should have the expression >> itself now, not the base columns of the expression. >> >> There are many similar examples involving "enum columns" -- columns with a >>> limited set of choices, where the choices are not instances of another >>> model. >> >> >> I'm not sure of this one. >> >> - Anssi >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Django developers (Contributions to Django itself)" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/django-developers/FojuU0syO8Y/unsubscribe >> . >> To unsubscribe from this group and all its topics, send an email to >> django-develop...@googlegroups.com <javascript:>. >> To post to this group, send email to django-d...@googlegroups.com >> <javascript:>. >> Visit this group at http://groups.google.com/group/django-developers. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-developers/CALMtK1FqTkdmnXNYvjZ8U_QF9%2BWzrMCb1DDFQU5WB4SiKPX06g%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/django-developers/CALMtK1FqTkdmnXNYvjZ8U_QF9%2BWzrMCb1DDFQU5WB4SiKPX06g%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/15f6552c-992f-4073-9802-0613ca498777%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.