Postgres UPSERT (INSERT or UPDATE) only if value is different

前端 未结 6 1563
你的背包
你的背包 2021-02-05 17:26

I\'m updating a Postgres 8.4 database (from C# code) and the basic task is simple enough: either UPDATE an existing row or INSERT a new one if one doesn\'t exist yet. Normally I

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 17:40

    Start a transaction. Use a select to see if the data you'd be inserting already exists, if it does, do nothing, otherwise update, if it does not exist, then insert. Finally close the transaction.

提交回复
热议问题