#32277: Aggregate of aggregate not allowed in window functions
-------------------------------------+-------------------------------------
               Reporter:  Héctor     |          Owner:  nobody
  Pablos                             |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  window, aggregates
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When trying do something like

   {{{#!python
   Sum(Count('field_name'))
   }}}

 Django raises a FieldError exception with the message {{{Cannot compute
 Sum('count'): 'count' is an aggregate"}}}. That makes sense except when
 {{{Sum(Count())}}} is the expression of a Window function, where nesting
 two aggregates is a valid SQL expression:

   {{{#!python
   Window(expression=Sum(Count('field_name')), **omitted_window)
   }}}

 I may be missing some edge case here but would it be possible to check, in
 the django.db.aggregates.Aggregate Func resolve_expression method, whether
 the expression containing another aggregate is the main expression of a
 Window function and, in that case, allow the execution of the SQL? Or is
 there any way to circumvent this aggregation nesting limitation in window
 functions?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32277>
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/049.122495070d1ec74b2eddaabfe73b524b%40djangoproject.com.

Reply via email to