On Tue, Nov 12, 2024 at 3:38 PM yudhi s <learnerdatabase99@xxxxxxxxx> wrote: > Can you share your thoughts on how exactly this merge query can possibly cause the duplicate key error? MERGE doesn't take any special precautions to avoid such unique violations. ON CONFLICT does. It really is that simple. Your app will be prone to the same sorts of errors (at READ COMMITTED isolation level) if you do inserts conditioned on the absence of an existing/conflict row. You'd have to retry the statement to plug the race condition, which is how Postgres users did upserts prior to the introduction of ON CONFLICT DO UPDATE. -- Peter Geoghegan