diff options
Diffstat (limited to 'django/contrib/postgres/aggregates/general.py')
-rw-r--r-- | django/contrib/postgres/aggregates/general.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/django/contrib/postgres/aggregates/general.py b/django/contrib/postgres/aggregates/general.py index 6ff6727bd4..5d420505eb 100644 --- a/django/contrib/postgres/aggregates/general.py +++ b/django/contrib/postgres/aggregates/general.py @@ -1,7 +1,8 @@ +from django.contrib.postgres.fields import JSONField from django.db.models.aggregates import Aggregate __all__ = [ - 'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'StringAgg', + 'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'JsonAgg', 'StringAgg', ] @@ -30,6 +31,16 @@ class BoolOr(Aggregate): function = 'BOOL_OR' +class JsonAgg(Aggregate): + function = 'JSONB_AGG' + _output_field = JSONField() + + def convert_value(self, value, expression, connection, context): + if not value: + return [] + return value + + class StringAgg(Aggregate): function = 'STRING_AGG' template = "%(function)s(%(distinct)s%(expressions)s, '%(delimiter)s')" |