column correspondence in UNIONs, self-referential subqueries

Issue #1268 resolved
Mike Bayer repo owner created an issue

We expect that column correspondence for a UNION would place higher precedence on the SELECT at the top. But the current proxy_set/corresponding_column implementation has no awareness of "position" in this way. CompoundSelect should probably try to resolve ambiguities like this when it first creates the proxy sets, but they have to take into account the full lineage of each column in the select.

from sqlalchemy import *
from sqlalchemy.sql import table, column

t1 = table('t', 
    column('f1', Integer),
    column('f2', Integer)
)

u = union(
            select([t1.c.f2](t1.c.f1,)),
            select([t1.c.f1](t1.c.f2,))
        )

assert u.corresponding_column(t1.c.f1) is u.c.f1
assert u.corresponding_column(t1.c.f2) is u.c.f2

Comments (3)

  1. Mike Bayer reporter

    Before I post the fix, let's also add this seemingly unrelated failure:

    from sqlalchemy import *
    from sqlalchemy.sql import table, column
    
    t1 = table('t1', 
        column('f1', Integer),
        column('f2', Integer)
    )
    
    a1 = t1.alias('a1')
    
    s= select([t1](a1,), use_labels=True)
    
    assert s.corresponding_column(t1.c.f1) is s.c.t1_f1
    assert s.corresponding_column(a1.c.f1) is s.c.a1_f1
    
  2. Log in to comment