mysql - Is there a `USING` clause in SQLAlchemy core? -
i'm using sqlalchemy on mysql database. there way can use mysql's using
clause join tables?
e.g.
select * join b using(some_id, other_id);
short answer
no.
longer answer
you write compiler extension render statement, don't think worth effort. explanation below.
in mysql don't have use using
join tables. it's considered syntactic sugar on more general on
construct.
sqlalchemy not include handling special case join columns have same name (main use-case using using
). uses general approach (on
).
as sqlalchemy render on
statements you, , in cases infer join-relationships table
definitions , obviating need specify join condition at all, not more work.
example
t1 = table('a', metadata, column('id', integer)) t2 = table('b', metadata, column('id', integer), column('fk', integer, foreignkey('a.id'))) sel = select([ t1.c.id, t2.c.id, ]).select_from( t1.join(t2) # please note, no on or using ) print sel
will result in
select a.id, b.id join b on a.id = b.fk
Comments
Post a Comment