Unfortunately this syntax is not supported. Your current usage of individual scalar subqueries is the SQL standard version and is the most straightforward way. Or of course using straight text.
You can also write a custom compiler for Update:
from sqlalchemy import and_, select
from sqlalchemy.sql.expression import table, column, UpdateBase, _generative
from sqlalchemy.ext.compiler import compiles
class CustomUpdate(UpdateBase):
def __init__(self, table, source, dest):
self.table = table
self.source = source
self.dest = dest
self._whereclause = None
@_generative
def where(self, whereclause):
if self._whereclause is not None:
self._whereclause = and_(self._whereclause,whereclause)
else:
self._whereclause = whereclause
@compiles(CustomUpdate)
def _cust_update(elem, compiler, **kw):
t = "UPDATE " + compiler.process(elem.table, asfrom=True) + \
" SET (" + ",".join(
compiler.process(c) for c in elem.dest
) + ") = (" + compiler.process(elem.source.correlate(elem.table)) + ")"
if elem._whereclause is not None:
t += " WHERE " + compiler.process(elem._whereclause)
return t
t1 = table('t1', column('a'), column('b'), column('c'))
t2 = table('t2', column('a'), column('b'))
print CustomUpdate(
t1,
select([t2.c.a, t2.c.b]).where(t2.c.b==t1.c.a),
[t1.c.a, t1.c.b]
).where(t1.c.c==12)
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>