Opened 4 years ago

Closed 2 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 4 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 4 years ago by anonymous


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

comment:3 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to 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:4 Changed 2 years ago by jorgecarleitao

This can be documented when ticket #14030 is addressed.

comment:5 Changed 2 years ago by jorgecarleitao

comment:6 Changed 2 years ago by timo

  • Resolution set to worksforme
  • Status changed from new to closed

Yep, that looks like it.

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