Upsert with a transaction

前端 未结 2 1524
耶瑟儿~
耶瑟儿~ 2020-12-02 03:00

I\'m using Spring with PostgreSQL and I try to do a sort of UPSERT by using a code like this:

jt.update(\"delete from A where id = 1\")
jt.update(\"insert in         


        
2条回答
  •  旧巷少年郎
    2020-12-02 03:49

    I wrote a rather large blogpost about it, so even though I might get downvotes for links, read this.

    The gist is that transactions do not help in here (at least by default), and while it is possible to write correct upsert, it's actually pretty tricky.

提交回复
热议问题