From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Brent Wood <Brent(dot)Wood(at)niwa(dot)co(dot)nz>, Andrew Hardy <andrew(dot)hardy(at)sabstt(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: DELETING then INSERTING record with same PK in the same TRANSACTION |
Date: | 2022-02-09 20:05:03 |
Message-ID: | 2d136d22-e82d-c691-775b-c12aa29b079c@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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 "public.animals"
Column | Type | Collation | Nullable | Default
--------+------------------------+-----------+----------+---------
id | integer | | not null |
cond | character varying(200) | | not null |
animal | character varying(200) | | not null |
Indexes:
"animals_pkey" PRIMARY KEY, btree (id)
delete from animals where id = 1;
DELETE 1
insert into animals values (1, 'great', 'opossum');
INSERT 0 1
>
> Check if the error is generated during the transaction or at the commit
> stage, run it without the commit, rollback instead to check this.
>
> I don't see how you can do this within a transaction, someone else might?
>
>
>
> Brent Wood
>
> Principal Technician, Fisheries
> NIWA
> DDI: +64 (4) 3860529
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2022-02-09 20:47:26 | Re: DELETING then INSERTING record with same PK in the same TRANSACTION |
Previous Message | Andrew Hardy | 2022-02-09 20:01:59 | Re: DELETING then INSERTING record with same PK in the same TRANSACTION |