#26067: Orderable ArrayAgg and StringAgg
-------------------------------------+-------------------------------------
Reporter: fdh | Owner:
Type: New feature | Status: new
Component: contrib.postgres | Version:
Severity: Normal | Resolution:
Keywords: ArrayAgg StringAgg | Triage Stage:
ordering | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by fdh):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> 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.
New description:
The Postgres-specific ArrayAgg and StringAgg aggregations were added in
[https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/aggregates/
Django 1.9].
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#comment:1>
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/061.0c1a6d2b81e3b1deffabe10463167d49%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.