In the previous chapter, we've discussed approximately how to use multiple tables. So we continue a step in addition and research multiple table updates on this bankruptcy.
Using SQLAlchemy’s desk item, a couple of table can be specified in WHERE clause of update() technique. The PostgreSQL and Microsoft SQL Server help UPDATE statements that check with multiple tables. This implements “UPDATE FROM” syntax, which updates one desk at a time. However, extra tables can be referenced in an additional “FROM” clause within the WHERE clause at once. The following traces of codes give an explanation for the concept of more than one desk updates genuinely.
stmt = students.update().\
values({
students.c.name:'xyz',
addresses.c.email_add:'abc@xyz.com'
}).\
where(students.c.id == addresses.c.id)
The update object is equivalent to the following UPDATE query −
UPDATE students
SET email_add = :addresses_email_add, name = :name
FROM addresses
WHERE students.id = addresses.id
As a long way as MySQL dialect is worried, a couple of tables can be embedded into a single UPDATE assertion separated by a comma as given beneath −
stmt = students.update().\
values(name = 'xyz').\
where(students.c.id == addresses.c.id)
The following code depicts the resulting UPDATE question −
'UPDATE students SET name = :name
FROM addresses
WHERE students.id = addresses.id'
SQLite dialect however doesn’t help more than one-desk standards inside UPDATE and indicates following error −
NotImplementedError: This backend does not support multiple-table criteria within UPDATE