On Tuesday, December 8, 2015 at 2:52:07 PM UTC+2, Josh Smeaton wrote:
>
> Yeah I'm wary that a lot of the problems with extra() will be replicated
> by users switching to RawSQL() instead. It won't handle realiasing or group
> by correctly.
>
The group by case we can fix by creating a separate RawAggregate class, or
by adding aggregate flag to RawSQL. The hardcoding of column and table
names, and the realisasing problem can be solved with refsql style
annotations: qs = Author.objects.annotate( casewhen=RefSQL("case when {
{name}} = %s then height else weight end", ('Anssi',),
output_field=models.IntegerField()) ).order_by('name')(from
https://github.com/akaariai/django-refsql/blob/master/testproject/testproject/tests.py).
The idea is quite simply that instead of using hardcoded table.col
references in the code, you use normal Django lookups, and refsql converts
those to Col expressions.
But, whenever possible we should provide real expressions.
- Anssi
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" 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].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/5c5d7dd2-16fa-4495-8d3d-e6395b01681c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.