Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-10 Thread Andrew Hardy
As requested here is a full script and the issue does not arise. My sincere apologies it appears the issue is most likely with my client programming code. My first ever post here. I shall definitely be providing a full working SQL script from the very start on any future post. Many thanks and apo

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread David G. Johnston
On Wed, Feb 9, 2022 at 2:24 PM Thomas Kellerer wrote: > David G. Johnston schrieb am 09.02.2022 um 21:47: > > You cannot defer uniqueness checks to transaction commit so either it > > is going to fail on the insert or it will not fail at all. > > You can defer unique constraints, but not primary

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread Thomas Kellerer
David G. Johnston schrieb am 09.02.2022 um 21:47: You cannot defer uniqueness checks to transaction commit so either it is going to fail on the insert or it will not fail at all. You can defer unique constraints, but not primary key constraints. create table t ( id integer ); alter table t

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread Bryn Llewellyn
> david.g.johns...@gmail.com wrote: > > The convention on these lists is to inline or bottom post (and to trim the > reply to just the pertinent parts). Just for completeness, I expected this test to run without error. (I tried it in PG Version 14.1). create table t(k int primary key, v text n

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread David G. Johnston
The convention on these lists is to inline or bottom post (and to trim the reply to just the pertinent parts). On Wed, Feb 9, 2022 at 12:33 PM Brent Wood wrote: > Because both statements are in the transaction, the delete is not fully > actioned until the commit. So it still exists in the table

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread Adrian Klaver
On 2/9/22 10:34, Brent Wood wrote: My take on this... Because both statements are in the transaction, the delete is not fully actioned until the commit. So it still exists in the table when you try to insert the record with the duplicate key. No: \d animals Table "publ

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread Andrew Hardy
Really appreciate the input thank you. I shall try to provide a full script, I guess if the cascades are relevant in going to have to also provide all of the indirect table creations and all of the earlier inserts to those various tables. At the very least I'll try to provide a fuller error messa

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread Brent Wood
11 To: pgsql-general@lists.postgresql.org Subject: DELETING then INSERTING record with same PK in the same TRANSACTION Hi, When I: Begin a transaction DELETE from where id (PK) = INSERT INTO VALUES () ... ... ... COMMIT I get insert into "itinerary" ("dk", "locator

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread David G. Johnston
On Wed, Feb 9, 2022 at 11:12 AM Andrew Hardy wrote: > Do I need some particular kind of settings on my transaction to be able to > delete and insert afresh in the same transaction? > No. I cannot reproduce your claim with a trivial example on stock 13.5. You will need to be less vague and at l

Re: DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread Adrian Klaver
On 2/9/22 10:11 AM, Andrew Hardy wrote: Hi, When I: Begin a transaction DELETE from where id (PK) = INSERT INTO VALUES () ... ... ... COMMIT I get insert into "itinerary" ("dk", "locator") values ($1, $2) - duplicate key value violates unique constraint "itinerary_pkey" = itinerary? W

DELETING then INSERTING record with same PK in the same TRANSACTION

2022-02-09 Thread Andrew Hardy
Hi, When I: Begin a transaction DELETE from where id (PK) = INSERT INTO VALUES () ... ... ... COMMIT I get insert into "itinerary" ("dk", "locator") values ($1, $2) - duplicate key value violates unique constraint "itinerary_pkey" Do I need some particular kind of settings on my transaction