Opened 8 years ago

Closed 6 years ago

#19313 closed Bug (worksforme)

Count Aggregation documentation

Reported by: ebertti@… 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


add something in the documentation talking about the possibility of using distinct aggregation done by count.


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 Changed 8 years ago by Aymeric Augustin

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?


comment:2 Changed 8 years ago by anonymous


distinct by column name isn't suported by mysql backend.

comment:3 Changed 8 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

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:4 Changed 6 years ago by jorgecarleitao

This can be documented when ticket #14030 is addressed.

comment:5 Changed 6 years ago by jorgecarleitao

comment:6 Changed 6 years ago by Tim Graham

Resolution: worksforme
Status: newclosed

Yep, that looks like it.

Note: See TracTickets for help on using tickets.
Back to Top