#26602: RawSQL window functions break count()
----------------------------------------------+----------------------------
Reporter: daggaz | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords: QuerySet.extra
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+----------------------------
I wanted to annotate my objects with a running total:
{{{
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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26602>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.f4858ef3ef543c8df4932374a01b27e3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.