#24662: Sum() returns True/False when used with BooleanField & MySQL
-------------------------------------+-------------------------------------
     Reporter:  chriskief            |                    Owner:  marco-
                                     |  santamaria
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.8
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by jarshwah):

 * stage:  Unreviewed => Accepted


Comment:

 SUM(bool_field) on Oracle will return 1 also, because bools in Oracle are
 just a bit (1 or 0). Postgres has a specific bool type, and you can't sum
 a True/False without an implicit conversion to int. This is why I say
 SUM(bool) is only accidentally supported for a subset of databases. The
 field type that is returned is based on the backend get_db_converters and
 the actual values that come back.

 Now, something needs to change here. What I would propose to do is:

 1) Document that SUM(bool) is not supported in some way. Perhaps by
 documenting that SUM can only be applied to numeric types.
 2) Raise a warning if SUM(bool_field) is used with the suggestion to
 convert it to COUNT(bool_field)
 3) Begin to deprecate the ability to SUM(bool_field) (an extension of 2)
 above).

--
Ticket URL: <https://code.djangoproject.com/ticket/24662#comment:7>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.7c3a38fb07fcfd0e8131113f8f131082%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to