Opened 19 years ago
Closed 18 years ago
#1435 closed enhancement (duplicate)
[patch] Add aggregate function support.
Reported by: | 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: | no | UI/UX: | no |
Description (last modified by )
See my post on the Django Developers Forum describing the proposed extensions.
http://groups.google.com/group/django-developers/browse_frm/thread/245a37912cf8d4e3/64473bd51d00ff84#64473bd51d00ff84
http://groups.google.com/group/django-developers/browse_frm/thread/d0b41c6babb720a3/b30bb60249fce8d0#b30bb60249fce8d0
Attachments (2)
Change History (12)
comment:1 by , 19 years ago
Description: | modified (diff) |
---|---|
Summary: | Add Aggregate Function support. → [path] Add aggregate function support. |
by , 19 years ago
Attachment: | agg_funcs.diff added |
---|
comment:2 by , 19 years ago
Summary: | [path] Add aggregate function support. → [patch] Add aggregate function support. |
---|
comment:3 by , 19 years ago
comment:4 by , 19 years ago
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:6 by , 18 years ago
Cc: | added |
---|
comment:8 by , 18 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
I think this is close to being ready, but needs documentation and testing.
comment:9 by , 18 years ago
Triage Stage: | Accepted → Design 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 by , 18 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I'm closing this ticket in favour of #3566, which is a duplicate that seems to have a larger discussion around it.
(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.