#26067: Orderable ArrayAgg and StringAgg
---------------------------------+-----------------------------------------
     Reporter:  fdh              |      Owner:
         Type:  New feature      |     Status:  new
    Component:                   |    Version:
  contrib.postgres               |
     Severity:  Normal           |   Keywords:  ArrayAgg StringAgg ordering
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+-----------------------------------------
 The [http://www.postgresql.org/docs/9.0/static/functions-aggregate.html
 documentation] of Postgres 9.0 first mentions the possibility of ordering
 the results within aggregations such as ARRAY_AGG and STRING_AGG.

 This could be useful in some cases.
 For example: it could make sense to perform a StringAgg in lexicographical
 order in some cases.

 The basic format of ordering within aggregations in SQL is quite simple:
 {{{
 #!sql
 SELECT ARRAY_AGG(some_field ORDER BY some_field ASC) FROM table;
 SELECT ARRAY_AGG(some_field ORDER BY some_field DESC) FROM table;
 SELECT ARRAY_AGG(some_field ORDER BY other_field ASC) FROM table;
 }}}

 It would be nice if the above would be supported as follows:
 {{{
 #!python
 Model.objects.aggregate(ArrayAgg(some_field, order_by='some_field'))
 Model.objects.aggregate(ArrayAgg(some_field, order_by='-some_field'))
 Model.objects.aggregate(ArrayAgg(some_field, order_by='other_field'))
 }}}

 where order_by is an optional parameter. If it not specified, behavior can
 remain unchanged from the current implementation.

 As noted by Josh Smeaton in the [https://groups.google.com/forum/#!topic
 /django-developers/YCSDX3GApBM mailinglist] discussion for this feature,
 any ordering added within '''may''' need to be contributed to GROUP BY.
 This might require some investigation.

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

Reply via email to