#26192: Cannot order query by constant value
-------------------------------------+-------------------------------------
     Reporter:  srkunze              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.8
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by srkunze):

 * status:  closed => new
 * resolution:  invalid =>


Comment:

 > I don't see what the use of ordering by a constant string value is.

 Reducing code complexity (e.g. fewer ifs).

 The code overview from #26192:

 {{{
 # 1 create complex queryset
 ... more code
 # 2 annotate and add extra where
 ... more code
 # 3 add order (maybe referring to the extra column)
 ... more code
 # 4 wrap paginator around queryset
 ... more code
 # 5 create values_list of paged queryset
 ... more code
 # 6 evaluate <<<< crash
 }}}


 The code above spread over several files and few thousand lines builds up
 a quite complex query.

 Each point contribute to the final queryset (actually more than one
 queryset). In order to reduce coupling and code complexity, adding a
 constant column make things straightforward (otherwise we would need to
 check if the column was added).

 > it looks like this is a database limitation.

 Are you sure? From what I know of SQL, it's possible to order by column
 name (a string) or by column index (a number). Django just creates invalid
 SQL.

 Why does Django not refer the column order_by by name (or index) and
 instead inserts a value?

--
Ticket URL: <https://code.djangoproject.com/ticket/26192#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/065.4a6f0e2fbf3983d19ba84369166a86e1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to