Opened 12 years ago
Closed 11 years ago
#19313 closed Bug (worksforme)
Count Aggregation documentation
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.4 |
Severity: | Normal | Keywords: | aggregation |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
add something in the documentation talking about the possibility of using distinct aggregation done by count.
like:
Number of authors by category:
Author.objects.values('post__category__name').aggregate(qtd=Count('id', distinct=True))
There is nothing on the internet or in the documentation and talking something about it. I find that looking at the code.
Change History (6)
comment:1 by , 12 years ago
comment:3 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
I'm comfortable calling this an oversight on my part. SELECT COUNT(DISTINCT foo) FROM table is different to SELECT DISTINCT COUNT(foo) FROM table, and support for distinct counts was a deliberate decision.
Although it's a feature that may not be universally available on all databases, it is useful on those databases that support it.
comment:5 by , 11 years ago
Forget previous comment.
Isn't this documented in Count, https://docs.djangoproject.com/en/1.6/ref/models/querysets/#django.db.models.Count.distinct, which is different from distinct, https://docs.djangoproject.com/en/1.6/ref/models/querysets/#distinct ?
Internal APIs aren't documented because they're subject to change without warning.
Could you check if the following query — which only uses documented APIs — achieves the same result?