#26658: "When Case" query generating rule in duplicate
-------------------------------------+-------------------------------------
Reporter: imaia | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jarshwah):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Can you please provide more information, like the SQL you're seeing and
the SQL you expect?
Also, When(Case()) isn't valid. When are child objects of Case. I think
your ordering of values() clauses is also off. The query should be
something like:
{{{
Model.objects.annotate(value=Case(When(something=number, then=1),
default=0, output_field=IntegerField())).values('field',
'value').annotate(count=Count('field'), mysum=Sum('value'))
}}}
A `values()` clause implies the grouping (in GROUP BY). By annotating a
non-aggregate later you mess with the grouping and the select list. Can
you try this query above, and respond with the actual sql and desired sql
if there's still an issue please?
I'm not sure if what you wrote is just a typo or not,
--
Ticket URL: <https://code.djangoproject.com/ticket/26658#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 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/063.d9ec031bf8ce042c47c5e7e57e6d7789%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.