summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/aggregates/general.py
diff options
context:
space:
mode:
authorAndriy Sokolovskiy <me@asokolovskiy.com>2015-02-08 17:21:48 +0200
committerTim Graham <timograham@gmail.com>2015-03-30 10:44:37 -0400
commite4cf8c8420634d6f2dc8ce873246256ce635972d (patch)
treeea71c476b420df6497439609c496e80cd57c7725 /django/contrib/postgres/aggregates/general.py
parent931a340f1feca05b7a9f95efb9a3ba62b93b37f9 (diff)
downloaddjango-e4cf8c8420634d6f2dc8ce873246256ce635972d.tar.gz
Fixed #24301 -- Added PostgreSQL-specific aggregate functions
Diffstat (limited to 'django/contrib/postgres/aggregates/general.py')
-rw-r--r--django/contrib/postgres/aggregates/general.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/django/contrib/postgres/aggregates/general.py b/django/contrib/postgres/aggregates/general.py
new file mode 100644
index 0000000000..1dda69c449
--- /dev/null
+++ b/django/contrib/postgres/aggregates/general.py
@@ -0,0 +1,43 @@
+from django.db.models.aggregates import Aggregate
+
+__all__ = [
+ 'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'StringAgg',
+]
+
+
+class ArrayAgg(Aggregate):
+ function = 'ARRAY_AGG'
+
+ def convert_value(self, value, expression, connection, context):
+ if not value:
+ return []
+ return value
+
+
+class BitAnd(Aggregate):
+ function = 'BIT_AND'
+
+
+class BitOr(Aggregate):
+ function = 'BIT_OR'
+
+
+class BoolAnd(Aggregate):
+ function = 'BOOL_AND'
+
+
+class BoolOr(Aggregate):
+ function = 'BOOL_OR'
+
+
+class StringAgg(Aggregate):
+ function = 'STRING_AGG'
+ template = "%(function)s(%(expressions)s, '%(delimiter)s')"
+
+ def __init__(self, expression, delimiter, **extra):
+ super(StringAgg, self).__init__(expression, delimiter=delimiter, **extra)
+
+ def convert_value(self, value, expression, connection, context):
+ if not value:
+ return ''
+ return value