Monday, February 29, 2016

Re: more than one field for aggregates? (ArrayAgg, StringAgg)

Hi Tomasz,

I suppose you could implement `ROW` as a custom expression[1] and use it in
your `ArrayAgg` aggregate as follow:

from django.contrib.postgres.aggregates import ArrayAgg
from django.db.models import Expression

class Row(Expression):
    template = 'ROW(%(expressions)s)'

    # ...

MyModel.objects.aggregate(
    ArrayAgg(Row(F('field1'), F('field2'))),
)


Cheers,
Simon

[1] https://docs.djangoproject.com/en/1.9/ref/models/expressions/#writing-your-own-query-expressions

Le lundi 29 février 2016 19:31:15 UTC-5, Tomasz Nowak a écrit :
Hi!

Module django.contrib.postgres.aggregates provides classes for ARRAY_AGG and STRING_AGG PostgreSQL aggregates.

Is it possible to provide more than one field to these aggregates?
Like in SQL, where you can provide more fields ("row" is optional):

ARRAY_AGG(row(table.field1, table.field2))

Best wishes,
Tomasz

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e5a3e7a2-74b3-462c-8461-eba15aaf1bc1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment