2

I am using djagno postgres function from https://docs.djangoproject.com/en/3.0/ref/contrib/postgres/fields/

I need to use aggregation function in hstore field, but getting error...

Here is my models.py

    def get_default_dict():
        return {}


    class Post(models.Model):
        .................
        extra_details = HStoreField(default=get_default_dict)


        class Meta:
            db_table = 'post'

extra_details field save like {"abc":1}, {"abc":100}, {"abc":433}

Now i have to get the post object where extra_details['abc'] value are highest ( ex. 433)

I am tring to do like

   from django.db.models import Avg, Max

   Post.objects.filter(id__in=[1,2,3,4,5,..]).annotate(ab=Max('extra_details__abc'))

getting error

  *** django.db.utils.ProgrammingError: function max(hstore) does not exist
  LINE 1: ......."statistics", MAX("post..
  HINT:  No function matches the given name and argument types. You might need to add 
explicit type casts.

How can i use aggregate function in this situation?

Somil
  • 1,921
  • 1
  • 21
  • 35

0 Answers0