#26602: RawSQL window functions break count()
-------------------------------------+-------------------------------------
     Reporter:  daggaz               |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  QuerySet.extra       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by akaariai):

 I guess we could add Window annotations. The problem is that you can't
 actually filter on window functions, you need a subquery for that. That
 is:
 {{{
 select SUM(amount) OVER (ORDER BY created) as sum_amount
   from ...
  where sum_amount > 0
 }}}
 is illegal SQL. We'd need to write the query as:

 {{{
 select * from (select SUM(amount) OVER (ORDER BY created) as sum_amount
 from ...) subq
  where sum_amount > 0
 }}}

 I don't think we have machinery to do that easily right now.

 I'm OK adding window aggregates to Django if they fail loudly and clearly
 when one tries to filter over them. They could be useful even if you can't
 actually filter on the result.

 Maybe a new ticket is better for this than hijacking this ticket?

--
Ticket URL: <https://code.djangoproject.com/ticket/26602#comment:4>
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/064.9416a491d8dc4fff322983a6d3765e8b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to