Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 6, 2011 15:35:43

Vlastimil Z.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Ordering columns in from clause


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 tickethttp://code.djangoproject.com/ticket/11568was 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.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 6, 2011 16:21:34

Ian C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Ordering columns in from clause


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 tickethttp://code.djangoproject.com/ticket/11568was 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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support