I'm trying to write a select query which joins two tables. Let's say the first table is called 'users' and has a column called 'user_id'. Let's say the second table is called 'addresses' and has a two-column composite primary key on the columns ('user_id', 'address_type'). The 'address_type' column would be something like home, work, etc.
Now I want to OUTER join these two tables where the user_id's are equal but the address_type is a constant (for example, I'm only interested in 'home' addresses right now). I tried doing this by: outerjoin(User, Address, and_(User.c.user_id == Address.c.user_id, Address.c.address_type == bindparam('addr_type')) Unfortunately, this produces the following error: >> Module sqlalchemy.sql:2293 in _init_primary_key >> if p.references(c) or (c.primary_key and not p.primary_key): exceptions.AttributeError: '_BindParamClause' object has no attribute 'primary_key' I tried moving the "address_type == bindparam('addr_type')" clause to the "where" clause instead of the join condition, which winds up building a workable query, but unfortunately this query is not equivalent to the one I actually want. The problem is that, let's say I'm looking for 'home' addresses and the addresses table contains an address of type 'work' for user_id 1 but not one of type 'home'. When using the (non-working in sqlalchemy) outerjoin above, I should get a result row with all of the selected address columns as NULL, but when using the substituted "where" version, I get no rows returned at all (because the join condition matches the 'work' row, but then the "where" clause filters it out). Is this a bug in SQLAlchemy, or am I doing something wrong? I'm using SQLAlchemy 0.3.10. Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---