I'm using SQLAlchemy Core. A user prepares an "on" expression for a join query 
and passes it to a function. The goal of the function is to hide some messy 
details the must be done to perform the join. Part of these details include 
doing a subselect. So in the implentation, the subselect is turned into an 
alias, but now the on clause that was passed in no longer references the proper 
table. I'd like to know how to transform an expression so that all references 
to tableA are replaced with alias name tableB.

Pseudocode: 

cols = [... in terms of tableA and tableB]
onclause = tableA.c.colX == tableB.c.colX
alias = sqla.select(cols).alias('hi')

updated_onclause = magic(onclause, tableA, alias)


So I need magic() to return an expression equal to:

alias.c.colX == tableB.c.colX

My hack it to manipulate the generated sql and then use sqla.text(), which is 
certainly not ideal.

So how can I manipulate an arbitrary expression (intended for use as a join 
clause or where clause), replacing all appearances of a table with an alias of 
that same table?

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to