Re: Duplicate key error - Mailing list pgsql-general

From Peter Geoghegan
Subject Re: Duplicate key error
Date
Msg-id CAH2-WzmkdenBYr2L41EFUUYKFAjjFJcaHh=ANdwFcTqdAY35sg@mail.gmail.com
Whole thread Raw
In response to Re: Duplicate key error  (yudhi s <learnerdatabase99@gmail.com>)
List pgsql-general
On Tue, Nov 12, 2024 at 3:38 PM yudhi s <learnerdatabase99@gmail.com> 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



pgsql-general by date:

Previous
From: yudhi s
Date:
Subject: Re: Duplicate key error
Next
From: Kaare Rasmussen
Date:
Subject: A million users