On Nov 8, 2010, at 2:33 PM, Jon Nelson wrote:

> I'd like to translate a SQL statement:
> 
> UPDATE foo SET colA = bar.colB FROM bar WHERE foo.colC = bar.colC;
> 
> I get this far, but am not sure how to add the FROM:
> 
> stmt = foo_table.update()\
> .where( foo_table.c.colC == bar_table.c.colC )\
> .values( foo_table.c.colA = bar_table.c.colA )
> 
> 
> What do I need to do here?

We don't have out of the box support for PG and MySQL's extensions to UPDATE, 
though there's someone working on some extensions and patches you can try over 
at http://www.sqlalchemy.org/trac/ticket/1944 .

The SQL standard method of updating based on data from other tables is to use 
subqueries in the WHERE clause.  An example of that:  
http://www.sqlalchemy.org/docs/core/tutorial.html#correlated-updates . In this 
case you might want to phrase it as "WHERE colC IN (SELECT colC FROM b)".




> 
> -- 
> Jon
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> 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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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.

Reply via email to