﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
1517	Query result ordering on field in different table broken when doing join on same table	rfugger at gmail dot com	Adrian Holovaty	"(Using django 0.91/postgresql)

Doing a join on table X creates an alias like ""t1"" for table X in the SQL.  If I then order_by='X.something', I get the [http://www.postgresql.org/docs/8.1/interactive/queries-table-expressions.html following undesirable behaviour]:

-----
""The alias becomes the new name of the table reference for the current query — it is no longer possible to refer to the table by the original name. Thus

SELECT * FROM my_table AS m WHERE my_table.a > 5;

is not valid SQL syntax. What will actually happen (this is a PostgreSQL extension to the standard) is that an implicit table reference is added to the FROM clause, so the query is processed as if it were written as

SELECT * FROM my_table AS m, my_table AS my_table WHERE my_table.a > 5;

which will result in a cross join, which is usually not what you want.""
-----

Django must rename my order_by argument to account for the alias it has given the table.  It doesn't appear to be doing this."	defect	closed	Database layer (models, ORM)	0.91	normal	duplicate			Unreviewed	0	0	0	0	0	0
