#19493: annotate(Count()) does not work properly with django.db.backends.oracle
-------------------------------------+-------------------------------------
     Reporter:  kimvais@…            |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  1.4
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:
     Keywords:  oracle               |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by akaariai):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> An QuerySet operation like:
> models.SomeModel.objects.filter(somecharfield=value).values("someintegerfield").annotate(Count("someintegerfield"))
>
> return a QuerySet with no aggregate count, but multiple rows with
> someintegerfield__count=1
>
> The correct SQL would be: SELECT
> tablespace_somemodel.someintegerfield,COUNT(tablespace_somemodel.someintegerfield)
> AS someintegerfield__count FROM tablespace_somemodel WHERE
> tablespace_somemodel.somecharfield = 'value'  GROUP BY
> tablespace_somemodel.someintegerfield;
>
> This works fine on other backends.

New description:

 An QuerySet operation like:
 
models.SomeModel.objects.filter(somecharfield=value).values("someintegerfield").annotate(Count("someintegerfield"))

 return a QuerySet with no aggregate count, but multiple rows with
 `someintegerfield__count=1`

 The correct SQL would be:
 {{{
 SELECT tablespace_somemodel.someintegerfield,
 COUNT(tablespace_somemodel.someintegerfield) AS someintegerfield__count
   FROM tablespace_somemodel WHERE tablespace_somemodel.somecharfield =
 'value'
  GROUP BY tablespace_somemodel.someintegerfield;
 }}}

 This works fine on other backends.

--

Comment:

 What SQL do you get? settings.DEBUG = True + connection.queries should
 tell you the executed query easily.

 Quickly checking it seems a QuerySet with multiple rows having
 `someintegerfield__count=1` seems the correct answer for the query.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19493#comment:1>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to