Wednesday, May 4, 2011

ORDER_BY and SELECT

DISTINCT columns need to be specified in the SELECT field because of Postgres limitations.

http://old.nabble.com/order_by-with-distinct-behavior-in-orm-td20592224.html

The reason every field in the table is included is because that's how
GROUP BY works - any field that is in the query that isn't an
aggregate needs to be included in the group by. When you call
Table.objects...., this implies SELECT Table.id, Table.name, ... at
the database level. Some other fields are included in the GROUP BY to
accomodate the needs of order_by() and select_related(). 



http://groups.google.com/group/django-users/browse_thread/thread/15b3c24dddd2a2d5

No comments:

Post a Comment