Re: ON CONFLICT DO NOTHING RETURNING

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Peter Geoghegan <pg(at)bowt(dot)ie>
Cc: Peter Devoy <peter(at)3xe(dot)co(dot)uk>, "Psql_General (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: ON CONFLICT DO NOTHING RETURNING
Date: 2016-03-18 16:14:32
Message-ID: CAMkU=1wtMThFokLMzePw4a9D=YAyiScMVix-vdAipb+a=eSFRw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Mar 14, 2016 at 1:20 PM, Peter Geoghegan <pg(at)bowt(dot)ie> wrote:
> On Mon, Mar 14, 2016 at 12:28 PM, Peter Devoy <peter(at)3xe(dot)co(dot)uk> wrote:
>> Is there a reason DO NOTHING was not developed for use with RETURNING?
>
> I don't know what you mean. It should work fine with RETURNING.

He wants to retrieve a value from the conflicting row. Now getting
the value that caused the conflict should be easy, because you
provided it in the first place. But he wants a value from a
different column of the conflicting row than the column(s) on which
there is conflict. DO NOTHING RETURNING returns no rows. Which is
reasonable, because nothing was inserted. But it isn't what he wants.

I think the dummy update is his best bet, but it does seem like there
should be a better way. Maybe ON CONFLICT DO SELECT where the select
operates over the target row.

Cheers,

Jeff

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Iván Perdomo 2016-03-18 16:55:35 "Tardis" approach for history tables
Previous Message Tom Lane 2016-03-18 14:59:35 Re: spurious /dev/shm related errors on insert