#26458: The Avg aggregate should only automatically resolves its output field to
FloatField on numeric sources
-------------------------------------+-------------------------------------
Reporter: charettes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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
[https://groups.google.com/d/msg/django-users/BwkK7R1WXYU/k4b5nzNwAQAJ
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/26458>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.fe4d27aa1149e37ccccc03d8b384f3b7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.