Based on your avatar and description I'm guessing you're using Oracle. From this answer one can device the following SQLAlchemy concotion, if your join results in a key preserved view:
stmt = select([foo.c.bar.label('foo_bar'),
foo.c.baz.label('foo_baz'),
foobar.c.bar.label('foobar_bar'),
foobar.c.baz.label('foobar_baz')]).
where(foo.c.id == foobar.c.id)
update(stmt).values({stmt.c.foo_bar: stmt.c.foobar_bar,
stmt.c.foo_baz: stmt.c.foobar_baz})
which produces the following SQL:
UPDATE (SELECT foo.bar AS foo_bar,
foo.baz AS foo_baz,
foobar.bar AS foobar_bar,
foobar.baz AS foobar_baz
FROM foo, foobar
WHERE foo.id = foobar.id)
SET foo_bar=foobar_bar, foo_baz=foobar_baz
The labels are important since your tables share column names.
You can also produce your original target SQL:
from sqlalchemy import tuple_, select, exists
stmt = select([foobar.c.bar, foobar.c.baz]).where(foo.c.id == foobar.c.id)
foo.update().
values({tuple_(foo.c.bar, foo.c.baz).self_group(): stmt}).
where(exists(stmt))
The self_group()
call is important, as the compiler seems to omit the parentheses around the tuple, producing incorrect syntax, in this case. I added the WHERE clause in order to avoid updating foo rows with no matching foobar:
UPDATE foo SET (bar, baz)=(SELECT foobar.bar, foobar.baz
FROM foobar
WHERE foo.id = foobar.id) WHERE EXISTS (SELECT foobar.bar, foobar.baz
FROM foobar
WHERE foo.id = foobar.id)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…