﻿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	RawSQL window functions break count()	Jamie Cockburn	nobody	"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
}}}
"	Uncategorized	new	Database layer (models, ORM)	1.9	Normal		QuerySet.extra		Unreviewed	0	0	0	0	0	0
