summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/aggregates/general.py
diff options
context:
space:
mode:
authorFloris den Hengst <florisdenhengst@gmail.com>2016-07-05 11:47:24 +0200
committerTim Graham <timograham@gmail.com>2018-06-28 20:29:33 -0400
commit96199e562dcc409ab4bdc2b2146fa7cf73c7c5fe (patch)
treecb047cbe692bfe22a10b25b1336730079ec027bf /django/contrib/postgres/aggregates/general.py
parent2a0116266c4d81bd1cc4e3ea20efe9a7874f481b (diff)
downloaddjango-96199e562dcc409ab4bdc2b2146fa7cf73c7c5fe.tar.gz
Fixed #26067 -- Added ordering support to ArrayAgg and StringAgg.
Diffstat (limited to 'django/contrib/postgres/aggregates/general.py')
-rw-r--r--django/contrib/postgres/aggregates/general.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/django/contrib/postgres/aggregates/general.py b/django/contrib/postgres/aggregates/general.py
index 806ecd1b78..4b2da0b101 100644
--- a/django/contrib/postgres/aggregates/general.py
+++ b/django/contrib/postgres/aggregates/general.py
@@ -1,14 +1,16 @@
from django.contrib.postgres.fields import ArrayField, JSONField
from django.db.models.aggregates import Aggregate
+from .mixins import OrderableAggMixin
+
__all__ = [
'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'JSONBAgg', 'StringAgg',
]
-class ArrayAgg(Aggregate):
+class ArrayAgg(OrderableAggMixin, Aggregate):
function = 'ARRAY_AGG'
- template = '%(function)s(%(distinct)s%(expressions)s)'
+ template = '%(function)s(%(distinct)s%(expressions)s %(ordering)s)'
@property
def output_field(self):
@@ -49,9 +51,9 @@ class JSONBAgg(Aggregate):
return value
-class StringAgg(Aggregate):
+class StringAgg(OrderableAggMixin, Aggregate):
function = 'STRING_AGG'
- template = "%(function)s(%(distinct)s%(expressions)s, '%(delimiter)s')"
+ template = "%(function)s(%(distinct)s%(expressions)s, '%(delimiter)s'%(ordering)s)"
def __init__(self, expression, delimiter, distinct=False, **extra):
distinct = 'DISTINCT ' if distinct else ''