Ticket #26327: contrib_postgres_json_agg.patch

File contrib_postgres_json_agg.patch, 903 bytes (added by Tomasz Nowak, 9 years ago)
  • django/contrib/postgres/aggregates/general.py

    diff --git a/django/contrib/postgres/aggregates/general.py b/django/contrib/postgres/aggregates/general.py
    index 1dda69c..6b35c93 100644
    a b  
    11from django.db.models.aggregates import Aggregate
    22
     3import json
     4
    35__all__ = [
    4     'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'StringAgg',
     6    'ArrayAgg', 'BitAnd', 'BitOr', 'BoolAnd', 'BoolOr', 'JsonAgg', 'StringAgg',
    57]
    68
    79
    class BoolOr(Aggregate):  
    3032    function = 'BOOL_OR'
    3133
    3234
     35class JsonAgg(Aggregate):
     36    function = 'JSON_AGG'
     37
     38    def convert_value(self, value, expression, connection, context):
     39        if not value:
     40            return []
     41        return json.loads(value)
     42
     43
    3344class StringAgg(Aggregate):
    3445    function = 'STRING_AGG'
    3546    template = "%(function)s(%(expressions)s, '%(delimiter)s')"
Back to Top