On Thu, Jan 6, 2011 at 7:35 AM, Vlastimil Zima <vlastimil.z...@gmail.com> wrote:
> Recently I found out that distinct() can not be called on queries that
> are ordered as the result query is kind of
>
> SELECT DISTINCT table.id, table.ordering_column FROM table ORDER BY
> table.ordering_column ASC
>
> In ticket http://code.djangoproject.com/ticket/11568 was said that
> this will not be fixed, bacuse this is intentional behaviour of
> ordering.
>
>
> So code
>
> SomeModel.objects.order_by('ordering_column').values_list('pk')
>
> leads to SQL
>
> SELECT table.id, table.ordering_column FROM table ORDER BY
> table.ordering_column ASC
>
> instaed of simple
>
> SELECT table.id FROM table ORDER BY table.ordering_column ASC
>
> My question is, what is the intention? I could not find out any
> advantage that comes from this kind of query.

It is not valid SQL to order by a column that is not in the result set.

MySQL allows you to do that, but that is a MySQL-specific feature.
PostgreSQL, certainly, does not allow this, and there is no real
advantage gained (aside from a slightly smaller response) by excluding
the ordering column.



Regards,
Ian Clelland
<clell...@gmail.com>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to