1. Michael Bayer
  2. sqlalchemy
  3. Issues

Issues

Issue #116 resolved

subquery correlation a little too eager

Michael Bayer
repo owner created an issue

subqueries get their FROM's yanked out even when the enclosing query doesnt reference that table:

subq = users.select(order_by=[users.c.username](users.c.username), limit=2).alias('users')

s = select(
        [roles.c.role](subq.c.username,),
        from_obj = [               subq.join(roles, subq.c.username==roles.c.username)
        ](
)
)


the query I get is:

SELECT users.username, roles.role
FROM (SELECT users.username AS username ORDER BY users.username
LIMIT 2) AS users JOIN roles ON users.username = roles.username

adding "correlate=False" to the above subquery makes it work. also changing the name "users" to "ualias" makes it work as well, hmmmm...should this throw an exception that theres conflicting names for "user" ? or track the FROM objects on identity and not name?

Comments (1)

  1. Log in to comment