public inbox for [email protected]
help / color / mirror / Atom feedFrom: yudhi s <[email protected]>
To: Peter Geoghegan <[email protected]>
Cc: pgsql-general <[email protected]>
Subject: Re: Duplicate key error
Date: Wed, 13 Nov 2024 02:08:45 +0530
Message-ID: <CAEzWdqcG8wFcVCcW-7YVsPWxb-9uzHcKNmyYOdLEZ6o1MHC8Aw@mail.gmail.com> (raw)
In-Reply-To: <CAH2-Wz=bSrxrEF_xsz+jLgiqQqE=n2_PZPe-GzRsSz6k6-Vr9A@mail.gmail.com>
References: <CAEzWdqeKafRTLDSP-0Ffw8nijQPUXKpgaHxMXoqz0yEdad-2aA@mail.gmail.com>
<CAH2-Wz=bSrxrEF_xsz+jLgiqQqE=n2_PZPe-GzRsSz6k6-Vr9A@mail.gmail.com>
On Tue, Nov 12, 2024 at 1:35 AM Peter Geoghegan <[email protected]> wrote:
> On Mon, Nov 11, 2024 at 12:41 AM yudhi s <[email protected]>
> wrote:
> > So it means it will ensure no duplication happens for ID values, but
> still we are seeing "duplicate key" error. So what is the possible reason
> here or are we encountering any buggy behaviour here?
>
> MERGE doesn't actually make any promises about not getting unique
> violations. Only ON CONFLICT DO UPDATE (and ON CONFLICT DO NOTHING)
> make such a promise. That's the main reason why Postgres supports
> both.
>
>
Okay. But here in this Merge statement it should first compare the ON
clause which is the value of ID column and if its exists in the
target table then its a MATCH which means it will do the UPDATE and if
its not available in the target table then its a NOT MATCH and it will do
the INSERT, so i am wondering at what exact situation it will throw
duplicate key error. Also the WITH clause will only pick one record at a
time and run the MERGE, so it will only merge one record at a time and then
commit. Can you share your thoughts on how exactly this merge query can
possibly cause the duplicate key error?
view thread (6+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Duplicate key error
In-Reply-To: <CAEzWdqcG8wFcVCcW-7YVsPWxb-9uzHcKNmyYOdLEZ6o1MHC8Aw@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox