#14466: "ORA-00918: column ambiguously defined error" has reappeared in 1.2.3
------------------------------------------------+---------------------------
 Reporter:  biolsen                             |       Owner:  nobody    
   Status:  new                                 |   Milestone:  1.3       
Component:  Database layer (models, ORM)        |     Version:  1.2       
 Keywords:  Oracle, column ambiguously defined  |       Stage:  Unreviewed
Has_patch:  1                                   |  
------------------------------------------------+---------------------------
 It seems that the ORA-00918 error, regarding identical column names in
 multiple tables (where aliases are necessary for instance in nested result
 sets like SELECT * FROM (SELECT .. FROM ...) ), somehow has been
 reintroduced into the code since its resolution in ticked #7057.

 The following patch has resolved the issue in 1.2.3 (solution based on
 ticked #7057).

 In /django/db/models/sql/compiler.py:

 {{{
 --- 71,88 ----
           result = ['SELECT']
           if self.query.distinct:
               result.append('DISTINCT')
 +         # Below is a patch to the 1.2.3 code that, at least with Oracle
 +         # made selects with identical column names crash with a
 ambiguous
 +         # column name error. This error was corrected in previous
 versions
 +         # of Django, but seemed to be re-introduced with 1.2.3.
 +         if ordering:
 +             cols = [clause.split('.')[-1] for clause in out_cols]
 +             for index, col in enumerate(cols):
 +                 if cols.count(col) > 1:
 +                     col = '%s%d' % (col.replace('"', ''), index)
 +                     cols[index] = col
 +                     out_cols[index] = '%s AS %s' % (out_cols[index],
 col)
           result.append(', '.join(out_cols + self.query.ordering_aliases))
           result.append('FROM')
           result.extend(from_)
           params.extend(f_params)
 ***************
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14466>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to