SQLAlchemy ON DUPLICATE KEY UPDATE

前端 未结 9 1553
死守一世寂寞
死守一世寂寞 2020-11-27 15:53

Is there an elegant way to do an INSERT ... ON DUPLICATE KEY UPDATE in SQLAlchemy? I mean something with a syntax similar to inserter.insert().execute(lis

9条回答
  •  情深已故
    2020-11-27 16:28

    As none of these solutions seem all the elegant. A brute force way is to query to see if the row exists. If it does delete the row and then insert otherwise just insert. Obviously some overhead involved but it does not rely on modifying the raw sql and it works on non orm stuff.

提交回复
热议问题