#9799: django.db.models.sql.query.BaseQuery.get_count() works wrong with GROUP 
BY
------------------------------------------+---------------------------------
 Reporter:  syabro                        |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Database layer (models, ORM)  |     Version:  1.0       
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 Query produced by get_count is
 {{{
 #!mysql
 SELECT COUNT(*) FROM table
 }}}
 which returned one row, f.e. (5) . Ok, it's works.
 Lets add an GROUP BY statement:
 {{{
 #!mysql
 SELECT COUNT(*) FROM table GROUP BY field
 }}}
 It's returned an list of row with count of grouped rows, f.e. (4, 23, 1,
 1, 5)
 In ge_count we see
 {{{
 #!python
 data = obj.execute_sql(SINGLE)
 if not data:
     return 0
 number = data[0]
 }}}
 So it's return only first value of the list instead of list's width. With
 our example it's 5.
 Solutions are:
 1. Return cursor's row_count
 2. Modify query to
 {{{
 #!mysql
 SELECT (*) FROM (SELECT COUNT(*) FROM table GROUP BY field) AS t
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9799>
Django <http://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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to