title: Replace existing records in SQLAlchemy Core
body: <p>I want to replace existing records in a table with records from a new table that have the same key.</p>
  
  <p>In SQL, for example, I would just execute the following two statements:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>In Python, How would I do this using SQLAlchemy Core (NOT the ORM)?</p>
  
  <pre><code>OldTable.delete().????   
  OldTable.insert(NewTable.select()) ????
  </code></pre>
  
  <p>I'm afraid I'm totally lost.</p>
  
  <p>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.</p>