id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 26602 Provide a way to manage grouping with RawSQL Jamie Cockburn Manav Agarwal "I wanted to annotate my objects with a running total: {{{#!python class A(models.Model): amount = models.IntegerField() created = models.DateTimeField(auto_now_add=True) qs = A.objects.annotate(total=RawSQL(""SUM(amount) OVER (ORDER BY created)"", [])) }}} That works fine, and I get a running total for each object, but I cannot call `count()` on that queryset: {{{ >>> qs.count() Traceback... ProgrammingError: window functions not allowed in GROUP BY clause }}} Using `extra()`, I can get the same annotation behaviour as well being able to call `count()`: {{{ >>> qs = A.objects.extra(select={'total': 'SUM(amount) OVER (ORDER BY created)'}) >>> qs.count() 8 }}} " New feature closed Database layer (models, ORM) dev Normal needsinfo QuerySet.extra josh.smeaton@… Accepted 0 0 0 0 0 0