Re: Conflict detection in ON CONFLICT

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Nicolas ALBEZA <n(dot)albeza(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Conflict detection in ON CONFLICT
Date: 2016-01-06 22:05:22
Message-ID: CAMkU=1zPuOGoi4bk9gw=b2fc0CcC9SmKiXqrO5dRToW2A8OQpA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jan 6, 2016 at 10:48 AM, Nicolas ALBEZA <n(dot)albeza(at)gmail(dot)com> wrote:
> Hello,
>
> Is there any way for a client to know if a conflict happened in an ON
> CONFLICT DO UPDATE query ?

Here is one way:

create table foo (x int primary key, y text);

insert into foo values (3,'insert') on conflict (x) do update set
y='update' returning y;

I don't know how to do it without leaving an extra column of cruft
behind in the table.

Cheers,

Jeff

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ted Toth 2016-01-06 22:26:19 9.5rc1 RLS select policy on insert?
Previous Message balajishanmugam@live.in 2016-01-06 21:08:29 Re: Postgresql 9.3 not coming up after restart in centos