1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

boulder-oracle-sprint: Fixed "ORA-00918 : column ambiguously defined" errors by aliasing columns with duplicated names.

git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4277 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Boulder Sprinters 2007-01-03 19:17:58 +00:00
parent 58ba520f32
commit 68aaa5df72

View File

@ -134,6 +134,16 @@ def get_query_set_class(DefaultQuerySet):
if order_by:
sql.append("ORDER BY " + ", ".join(order_by))
# Look for column name collisions in the select elements
# and fix them with an AS alias. This allows us to do a
# SELECT * later in the paging query.
cols = [clause.split('.')[-1] for clause in select]
for index, col in enumerate(cols):
if cols.count(col) > 1:
col = '%s%d' % (col.replace('"', ''), index)
cols[index] = col
select[index] = '%s AS %s' % (select[index], col)
# LIMIT and OFFSET clauses
# To support limits and offsets, Oracle requires some funky rewriting of an otherwise normal looking query.
select_clause = ",".join(select)