#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
-------------------------------------+-------------------------------------

Comment (by akaariai):

 `Count(bool_field)` isn't the same as `sum(bool_field)`, what you need is
 `sum(case when true then 1 else 0 end)`. I think it is at least worth
 considering if we should support min, max and sum for boolean fields.
 Sum(bool_field) would be automatically converted to `sum(case when...)`
 expression, min would be `min(case when true then 1 else 0 end)` and the
 return value would be then converted to either True of False, likewise for
 max().

 The reason why I think this might be worth supporting is that this is what
 you get in Python. For example `sum([True, False, False, True]) == 2` and
 min and max work similarly to the above explanation, too.

--
Ticket URL: <https://code.djangoproject.com/ticket/24662#comment:8>
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.e78dcba2e0e5a3000e3d8a910ac91a72%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to