django-postgres-extra icon indicating copy to clipboard operation
django-postgres-extra copied to clipboard

Support for HStore aggregates

Open Photonios opened this issue 7 years ago • 0 comments

I am not sure how this is going to work, but it should be possible to aggregate multiple columns into a hstore field:

results = MyModel.objects.annotate(thing=HStoreAgg(text=F('otherthing__text'), id=F('otherthing__id'))

for row in results:
      print(row.thing.text)
      print(row.thing.id)

This should also work in combination with ArrayAgg:

results = MyModel.objects.annotate(things=ArrayAgg(HStoreAgg(text=F('otherthing__text'), id=F('otherthing__id')))

for row in results:
    for thing in row.things:
          print(row.thing.text)
          print(row.thing.id)

Which results in:

Photonios avatar Jun 08 '17 09:06 Photonios