关于sql:SQL-saveOrUpdate

MySQL:ON DUPLICATE KEY UPDATE
参考 https://blog.csdn.net/qq_2277…

PostgreSQL:ON CONFLICT
参考 https://blog.csdn.net/weixin_…

MyBatis:

<selectKey keyProperty="count" resultType="int" order="BEFORE">
    select count(1) as count from xxx where aaa=1
</selectKey>
<if test="count > 0">
    update set xxx
</if>
<if test="count == 0">
    INSERT INTO xxx
</if>

Ps:MyBatis的形式在遇到并发插入报反复key时,能够用重试的形式解决

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理