Created
October 6, 2022 15:16
-
-
Save morenoh149/70f584c6e772a78af98104fb4effaa1c to your computer and use it in GitHub Desktop.
django orm optimization count on aggregates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
results = myModel.objects.values().annotate( | |
group_representative=ArrayAggFirstElem('pk', distinct=True), | |
) | |
group_representatives = results.values_list('group_representative', flat=True) | |
assert_( | |
results.count() == group_representatives.count(), | |
'Aggregation Spec should partition the results space (no overlaps)' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment