Code

Opened 7 years ago

Closed 4 years ago

#5293 closed (wontfix)

adding sql functions to order_by clause handling

Reported by: rb.online@… Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords: order_by
Cc: sam@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

The attached patch enables the use of a sql function in a order_by clause.

example:
Publication.objects.order_by("-year(date)")
will produce the following SQL:
... ORDER BY YEAR(date) DESC

use case:
when ordering according to multiple fields to group by year, and then say by publication type, if we use the date to order, the publication type is used only if the whole date is the same.
to group publications by year in the order clause, I could not find a solution.
Publication.objects.order_by("-date.year", "author")
does not work but
Publication.objects.order_by("-year(date)", "author")
does.

I suspect there are other use cases.

caveats:
The provided patch does not changes the way the deprecated syntax for ordering is handled (in orderlist2sql)

Attachments (1)

sql_function_in_order_by.diff (1.6 KB) - added by rb.online@… 7 years ago.
patch

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by rb.online@…

patch

comment:1 Changed 7 years ago by Simon G. <dev@…>

  • Triage Stage changed from Unreviewed to Design decision needed
  • Version changed from 0.96 to SVN

comment:2 Changed 6 years ago by anonymous

  • Cc sam@… added

comment:3 Changed 4 years ago by Alex

  • Resolution set to wontfix
  • Status changed from new to closed

Wontfixing this, there is zero precedent in the API for allowing arbitrary SQL.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.