#12814: Missing ORDER BY in subselect ------------------------------------------+--------------------------------- Reporter: EsOsO | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: SVN Keywords: | Stage: Unreviewed Has_patch: 0 | ------------------------------------------+--------------------------------- Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) {{{ >>> from django.db import connection >>> from pokertour.models import Session, Entry >>> s = Session.objects.all()[:4] >>> s [<Session: Session 033>, <Session: Session 032>, <Session: Session 031>, <Session: Session 030>] >>> e = Entry.objects.filter(session__in=s) >>> e [<Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, <Entry: Entry object>, '...(remaining elements truncated)...'] >>> connection.queries [{'time': '0.005', 'sql': 'SELECT "pokertour_session"."id", "pokertour_session"."name", "pokertour_session"."slug", "pokertour_session"."date", "pokertour_session"."location_id" FROM "pokertour_session" ORDER BY "pokertour_session"."date" DESC LIMIT 4'}, {'time': '0.004', 'sql': 'SELECT "pokertour_entry"."id", "pokertour_entry"."player_id", "pokertour_entry"."session_id", "pokertour_entry"."cash_in", "pokertour_entry"."cash_out", "pokertour_entry"."bank_in", "pokertour_entry"."stack" FROM "pokertour_entry" WHERE "pokertour_entry"."session_id" IN (SELECT U0."id" FROM "pokertour_session" U0 LIMIT 4) LIMIT 21'}] >>> }}}
The subquery should return the same records as the first, instead it loses the order by clause:[[BR]] ...FROM "pokertour_session" ORDER BY "pokertour_session"."date" DESC LIMIT 4[[BR]] ...FROM "pokertour_session" U0 LIMIT 4 -- Ticket URL: <http://code.djangoproject.com/ticket/12814> Django <http://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 post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.