Re: problem with on conflict / do update using psql 14.4

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: Barry Kimelman <blkimelman(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: problem with on conflict / do update using psql 14.4
Date: 2022-09-24 16:40:23
Message-ID: 1E5122A4-E58F-40C3-B579-A0BBD8FFE065@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Sep 24, 2022, at 09:04, Barry Kimelman <blkimelman(at)gmail(dot)com> wrote:
> Unfortunately, that is exactly what I need to do, I need to modify the data on the 2nd request so that it also gets inserted.

The best approach is to optimistically insert the row, catch the error if there's a conflict, and modify the data and try again. If a row with the same conflict can come from multiple sessions, you'll need to decide how to handle the case that some other session "wins" and inserts the row, and you get a conflict again.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2022-09-24 17:34:15 Re: problem with on conflict / do update using psql 14.4
Previous Message Barry Kimelman 2022-09-24 16:04:14 Re: problem with on conflict / do update using psql 14.4