Skip to content

Cannot use aggregate over window functions since 4.2 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zchn opened this issue Mar 5, 2025 · 3 comments
Open

Cannot use aggregate over window functions since 4.2 #1

zchn opened this issue Mar 5, 2025 · 3 comments

Comments

@zchn
Copy link

zchn commented Mar 5, 2025

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"))
@zchn zchn changed the title URL conf is evaluated after form Metas 🔗 Cannot use aggregate over window functions since 4.2 Mar 5, 2025
@zchn
Copy link
Author

zchn commented May 24, 2025

@snipr-ben snipe it

Copy link

snipr-team bot commented May 24, 2025

snipr-ben is working on this issue (snipe task id: 683119c59b229c6f7a71c53e) ...

Copy link

snipr-team bot commented May 24, 2025

Created a new branch with the changes: snipr-ben-issue-1. You can create a PR from this branch using this link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant