I want to replace existing records in a table with records from a new table that have the same key.
In SQL, for example, I would just execute the following two statements:
DELETE O FROM OLD_TABLE T1
WHERE EXISTS (SELECT * FROM NEW_TABLE T2
WHERE T1.KeyPart1 = T2.KeyPart1
AND T1.KeyPart2 = T2.KeyPart2 )
INSERT OLD_TABLE
SELECT * FROM NEW_TABLE T2
WHERE NOT EXISTS (SELECT * FROM OLD_TABLE T1
WHERE T1.KeyPart1 = T2.KeyPart1
AND T1.KeyPart2 = T2.KeyPart2)
In Python, How would I do this using SQLAlchemy Core (NOT the ORM)?
OldTable.delete().????
OldTable.insert(NewTable.select()) ????
I'm afraid I'm totally lost.
P.S. I'm doing this in SQLAlchemy CORE because (a) there's a log of records, and (b) I want SQLAlchemy to handle the database dialect dependence.