⬅︎ Back to Django ORM optimization story on selecting the least possible
Try this:from django.contrib.postgres.aggregates import StringAggfrom django.db.models import Funcresult = Song.objects.filter( artist=artist).aggregate( names_hash=Func( StringAgg('name', ''), function='md5' ))
That's awesome! I'm not on my computer so I can't test it but it'd be fast.
See UPDATE above.
Best optimizationI start thinking to suggest this solution before reading the "Update" section.P.S. They added "MD5" database function in Django dev:https://docs.djangoproject.com/en/dev/ref/models/database-functions/#md5
Comment
Try this:
from django.contrib.postgres.aggregates import StringAgg
from django.db.models import Func
result = Song.objects.filter(
artist=artist
).aggregate(
names_hash=Func(
StringAgg('name', ''), function='md5'
)
)
Replies
That's awesome! I'm not on my computer so I can't test it but it'd be fast.
See UPDATE above.
Best optimization
I start thinking to suggest this solution before reading the "Update" section.
P.S. They added "MD5" database function in Django dev:
https://docs.djangoproject.com/en/dev/ref/models/database-functions/#md5