Opened 12 years ago

Closed 10 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

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 Aymeric Augustin, 12 years ago

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?

Author.objects.values('post__category__name').distinct('id').aggregate(qtd=Count('id'))

comment:2 by anonymous, 12 years ago

Hi!

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

comment:3 by Russell Keith-Magee, 12 years ago

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 by jorgecarleitao, 10 years ago

This can be documented when ticket #14030 is addressed.

comment:6 by Tim Graham, 10 years ago

Resolution: worksforme
Status: newclosed

Yep, that looks like it.

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