Thanks a lot, Michael. Really, I can make t = t1 or t = t2 and then use t in select()
On 12 Жов, 16:46, Michael Bayer <mike...@zzzcomputing.com> wrote: > replace_selectable can only swap in another selectable that's derived from > the original. Else there's no way to correlate columns between each. > > you can try doing it directly, where the column correlation is by name > (something SQLAlchemy doesn't ever do): > > from sqlalchemy.sql import visitors > > def replace(x): > if x is t1: # replace the table > return t2 > elif t1.c.contains_column(x): # replace columns in the table > return t2.c[x.key] > > s = visitors.replacement_traverse(s, {}, replace) > > There also are compilation ways to do this, building a subclass of Alias > which compiles to the new name without the "AS", this would be a little hacky. > > I also might be looking to adjust my application to not require a pattern > like this. Here it would likely mean varying between "t1" and "t2" before > "s" is created. > > On Oct 12, 2011, at 8:32 AM, sector119 wrote: > > > > > > > > > Hello. > > > Is it possible to replace some table with defferent one? > > I want to get the same query, with the same columns, having, order_by, > > where clauses but with different table name. > > > s.replace_selectable(t1, t1_alias) - works > > s.replace_selectable(t1, t2) - doesn't > > > 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 > > sqlalchemy+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/sqlalchemy?hl=en. -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.