Opened 11 years ago

Closed 10 years ago

#1435 closed enhancement (duplicate)

[patch] Add aggregate function support.

Reported by: rock@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: magic-removal
Severity: normal Keywords: aggregate sum count min max stddev avg
Cc: gary.wilson@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:

Attachments (2)

agg_funcs.diff (16.0 KB) - added by Jacob 11 years ago.
aggr_functions-r3897.diff (13.6 KB) - added by wiz 10 years ago.
updated patch for r3897 of trunk

Download all attachments as: .zip

Change History (12)

comment:1 Changed 11 years ago by Jacob

Description: modified (diff)
Summary: Add Aggregate Function support.[path] Add aggregate function support.

Changed 11 years ago by Jacob

Attachment: agg_funcs.diff added

comment:2 Changed 11 years ago by anonymous

Summary: [path] Add aggregate function support.[patch] Add aggregate function support.

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

(at the suggestion of Stephen Newey <stephen.newey@…>) One piece of aggregate functionality that doesn't directly map to an SQL query is 'exists' - i.e., select all objects where at least one object exists in the relation. This can be currently 'faked' using a query like:

Topic.objects.filter(articleidisnull=False).distinct()

but it would be nice if an 'exists' query clause were to be included as part of the aggregate effort. Something like:

Topic.objects.filter(articleexists=True)

or, more generally:

Topic.objects.filter(articlecount_gt=5)

selecting all topics with more than 5 articles.

comment:4 Changed 11 years ago by Russell Keith-Magee

Examples again, this time with wikiformatting:

Topic.objects.filter(article__id__isnull=False).distinct()

Topic.objects.filter(article__exists=True)

Topic.objects.filter(article__count_gt=5)

comment:5 Changed 10 years ago by Gary Wilson <gary.wilson@…>

milestone: Version 0.92Version 1.0

0.92 is long gone.

Changed 10 years ago by wiz

Attachment: aggr_functions-r3897.diff added

updated patch for r3897 of trunk

comment:6 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Cc: gary.wilson@… added

comment:7 Changed 10 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:8 Changed 10 years ago by Simon G. <dev@…>

Needs documentation: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

I think this is close to being ready, but needs documentation and testing.

comment:9 Changed 10 years ago by Russell Keith-Magee

Triage Stage: AcceptedDesign decision needed

This topic comes up from time to time in the django-users and django-dev mailing lists; while aggregate functions are something that we should be striving to add to Django, I am not happy with the patch suggested in this proposal.

The archives contain many discussions in which I have talked about my reservations on this patch;
This thread: http://groups.google.com/group/django-developers/browse_thread/thread/e53a62e1c73871b8/092e6168703e27c3

has at least one proposal for a more wide ranging approach.

comment:10 Changed 10 years ago by Russell Keith-Magee

Resolution: duplicate
Status: newclosed

I'm closing this ticket in favour of #3566, which is a duplicate that seems to have a larger discussion around it.

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