Opened 9 years ago
Closed 9 years ago
#26458 closed Cleanup/optimization (fixed)
The Avg aggregate should only automatically resolves its output field to FloatField on numeric sources
Reported by: | Simon Charette | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Before #24649 was fixed it was simply not possible to use the Avg
function on non-numeric sources. The *good enough* solution was to allow use of the output_field
kwarg and document it should be used when averaging DurationField
.
As DurationField
uses different underlying datatype for its storage (bigint, interval, ...) averaging on such fields might require or not an explicit output_field
and can be a source of confusion.
As the SQL AVG
function only defaults to using floating value datatype as a return value when numeric input is used I suggest adjusting the Avg
expression's output_field
resolution to only use FloatField
for default when its source field is an instance of one of Django's numerical field classes. This would lift the requirement of explicitly specifying an output_field
when averaging DurationField
on PostgreSQL.
Change History (4)
comment:1 by , 9 years ago
Has patch: | set |
---|
comment:2 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
https://github.com/django/django/pull/6413