SQL saveOrUpdate

Time:2021-9-27

MySQL:ON DUPLICATE KEY UPDATE
reference resourceshttps://blog.csdn.net/qq_2277…

PostgreSQL:ON CONFLICT
reference resourceshttps://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. When a duplicate key is inserted in a concurrent message, it can be solved by retry