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

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: DELETING then INSERTING record with same PK in the same TRANSACTION
Дата
Msg-id fea0c101-2313-eace-9b8f-d3d293154fee@aklaver.com
обсуждение исходный текст
Ответ на DELETING then INSERTING record with same PK in the same TRANSACTION  (Andrew Hardy <andrew.hardy@sabstt.com>)
Список pgsql-general
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



В списке pgsql-general по дате отправления:

Предыдущее
От: Brent Wood
Дата:
Сообщение: Re: DELETING then INSERTING record with same PK in the same TRANSACTION
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: DELETING then INSERTING record with same PK in the same TRANSACTION