I know it is a bit late.. but if someone is still looking for solutions.
FOR: ON DUPLICATE KEY UPDATE
ins = insert(/* table_name*/ ).values(/*your values(with PK)*/)
do_update_stmt = ins.on_duplicate_key_update(/*your values(with out PK)*/)
connection.execute(do_update_stmt)
On duplicate key update docs
The ON DUPLICATE KEY UPDATE clause of INSERT supported by MySQL is now supported using a MySQL-specific version of the Insert object
This wont be avaliable with sqlalchemy.insert()
.
FOR: INSERT IGNORE
This is a bit hacky but works just fine.
ins_address_stmt = insert(/* table_name*/ ).values(/*your values*/).
prefix_with('IGNORE')
Insert prefix_with
MySQL will suppress the error for duplicate primary key and gives a warning.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…