From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Andrew Hardy <andrew.hardy@sabstt.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: DELETING then INSERTING record with same PK in the same TRANSACTION
Date: Wed, 9 Feb 2022 10:37:42 -0800
Message-ID: <fea0c101-2313-eace-9b8f-d3d293154fee@aklaver.com> (raw)
In-Reply-To: <CAKxhU8isUe6NUs7i7dJzdVeHHoK417Sv=z7jUoHZMHbezG_VkA@mail.gmail.com>
References: <CAKxhU8isUe6NUs7i7dJzdVeHHoK417Sv=z7jUoHZMHbezG_VkA@mail.gmail.com>
On 2/9/22 10:11 AM, Andrew Hardy wrote:
> Hi,
>
> When I:
>
> Begin a transaction
> DELETE from <table> where id (PK) = <somevalue>
> INSERT INTO <table> VALUES (<values - same PK>)
> ...
> ...
> ...
> COMMIT
>
> I get
>
> insert into "itinerary" ("dk", "locator") values ($1, $2) - duplicate
> key value violates unique constraint "itinerary_pkey"
<table> = itinerary?
What fields is unique constraint "itinerary_pkey" actually pointing at?
There should be more to the error message. Can you provide the complete
message?
>
> Do I need some particular kind of settings on my transaction to be able
> to delete and insert afresh in the same transaction?
>
> In case it is relevant - the first delete will lead to cascaded deletes
> on children.
>
> Alternatively I wonder if I change the PK column value to
> "<somevalue>-FORDELETION" will I be free to insert under the same
> original PK value in the same transaction, then delete the FORDELETE
> item just before committing or will I hit the same issue?
>
> Thanks,
>
> Andrew
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, andrew.hardy@sabstt.com
Subject: Re: DELETING then INSERTING record with same PK in the same TRANSACTION
In-Reply-To: <fea0c101-2313-eace-9b8f-d3d293154fee@aklaver.com>
References: <CAKxhU8isUe6NUs7i7dJzdVeHHoK417Sv=z7jUoHZMHbezG_VkA@mail.gmail.com> <fea0c101-2313-eace-9b8f-d3d293154fee@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox