#34717: Cannot use aggregate over window functions since 4.2
-------------------------------------+-------------------------------------
Reporter: younes-chaoui | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: aggregation, window | Triage Stage: Ready for
functions, psycopg | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by younes-chaoui:
Old description:
> After upgrading to Django 4.2, I encountered an exception when executing
> ORM queries that involve aggregates over Window functions. The specific
> error was `psycopg2.errors.GroupingError: aggregate function calls cannot
> contain window function calls`
>
> Dependencies :
>
> psycopg2 version: 2.9.3
> django version: 4.1.9
> PostgreSQL version: 13.4
>
> Example Code:
>
>
> {{{
> queryset = queryset.annotate(
> cumul_DJR=Coalesce(Window(Sum("DJR"), order_by=F("date").asc()), 0.0)
> )
>
> aggregate = queryset.aggregate(
> DJR_total=Sum("DJR"),
> cumul_DJR_total=Sum("cumul_DJR")
> )
> }}}
New description:
After upgrading to Django 4.2, I encountered an exception when executing
ORM queries that involve aggregates over Window functions. The specific
error was `psycopg2.errors.GroupingError: aggregate function calls cannot
contain window function calls`
Dependencies :
psycopg2 version: 2.9.3
django version: 4.2.3
PostgreSQL version: 13.4
Example Code:
{{{
queryset = queryset.annotate(
cumul_DJR=Coalesce(Window(Sum("DJR"), order_by=F("date").asc()), 0.0)
)
aggregate = queryset.aggregate(
DJR_total=Sum("DJR"),
cumul_DJR_total=Sum("cumul_DJR")
)
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34717#comment:8>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018996f98f6a-9d2d325b-aa88-49ec-b55b-02025c947f36-000000%40eu-central-1.amazonses.com.