#2479: [patch] add sum() method to query set ( SELECT SUM( fieldname .... )
-----------------------------------------------+----------------------------
Reporter: Simon Greenhill, [EMAIL PROTECTED] | Owner: adrian
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Database wrapper | Version: SVN
Severity: minor | Resolution:
Keywords: |
-----------------------------------------------+----------------------------
Comment (by mtredinnick):
Before you go too far here: firstly, having various aggregate functions is
indeed something we want to incorporate. The API may need a bit of
thought, though (for example, should it only work like count(), or should
some kind of sub-filtering be possible?).
Secondly, query.py is on the operating table at the moment being
refactored, so this will need to wait a few more days at least and then be
rebased against the current code (although, admittedly, the change isn't
too intrusive, so that shouldn't be too hard). Thinking about what it will
look like if we also add avg(), max(), ..., etc, though, it may be that
one method of this length per aggregate starts to get crazy. We need to
think about that.
Thirdly, stop with the casting to int! If a field contains floats, your
version of sum() is going to get the answer wrong.
Finally, I would prefer we do some kind of sanity checking on the target
field. The users of models are not required to have deep understanding of
SQL and databases (in theory), so we should provide sensible error
messages when we can. And sum(name) is rarely going to be the right thing.
--
Ticket URL: <http://code.djangoproject.com/ticket/2479>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---