Shubham
Shubham

Reputation: 3173

Array Aggregator function for Django using Postgresql

I am trying to use array_agg() function of postgresql in django 1.8, but could not bump into a solution as of now. What I have come across is this. But the function is broken. Also no luck with using raw query, because we need to always include the primary key of the table and the field I want to use array_agg() is not the primary key. I am stuck. Any help will be appreciated.

Upvotes: 3

Views: 748

Answers (1)

Shubham
Shubham

Reputation: 3173

The function has been added in django-dev.You can find it here.

class ArrayAgg(Aggregate):
    function = 'ARRAY_AGG'

    def convert_value(self, value, expression, connection, context):
        if not value:
            return []
        return value

For now you can add ^ as custom class.

Upvotes: 2

Related Questions