#28333: Filter and subquery for window expressions
-------------------------------------+-------------------------------------
     Reporter:  Mads Jensen          |                    Owner:  (none)
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  window orm filter    |             Triage Stage:  Accepted
  subquery GSoC                      |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by SafaAlfulaij):

 What I'm doing currently is this hack:

 Before:
 {{{
 #!python
 queryset =
 MyModel.objects.annotate(row=Window(expression=RowNumber())).filter(row__gt=1)
 }}}

 After:
 {{{
 #!python
 queryset = MyModel.objects.annotate(row=Window(expression=RowNumber()))
 sql, params = queryset.query.sql_with_params()
 queryset = queryset.raw(f"SELECT * FROM ({sql}) AS full WHERE row >= 1",
 params)
 }}}


 I don't see that it's bad to have this currently, with whatever
 limitations of `raw` documented in the `Window` filtering section, then
 add in more features if real use cases are provided.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28333#comment:20>
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/068.f797204460114154c4876d42a0d97548%40djangoproject.com.

Reply via email to