Want to delete data from multiple tables. As i understood, there is no way to do it via join/using in Postresql (currently 9.4). It is possible to delete only from one table at a time. Trying like this, but data was deleted only from t1, obviously. Maybe there is a mistake in my query.
DELETE FROM
shema.table1 t1
USING
shema.table2 t2,
shema.table3 t3,
shema.table4 t4
WHERE
t1.id = 111 AND
t1.id = t2.t1_id AND
t2.id = t3.t2_id AND
t2.id = t4.t2_id
Question 1. There is no simple way to delete data from multiple tables in one query with some feature like join in Postgresql?
Question 2. Query/ies is suppose to be run in python with sqlalchemy as raw SQL statements. Is there a difference how multiple DELETE statements will be execute?
As separate queries. Probably execute all queries within transaction.
from sqlalchemy import text
query_1 = text('DELETE ...')
query_2 = text('DELETE ...')
query_3 = text('DELETE ...')
engine.execute(query_1)
engine.execute(query_2)
engine.execute(query_3)
Or as one long statement
from sqlalchemy import text
queries = text(
'DELETE ...;'
'DELETE ...;'
'DELETE ...;'
)
engine.execute(queries)
FOREIGN KEYrelationships?