Re: UPSERT/RETURNING -> ON CONFLICT SELECT?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Geoghegan <pg(at)heroku(dot)com>
Cc: Bjørnar Ness <bjornar(dot)ness(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: UPSERT/RETURNING -> ON CONFLICT SELECT?
Date: 2016-07-13 17:12:21
Message-ID: 19806.1468429941@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Geoghegan <pg(at)heroku(dot)com> writes:
> On Wed, Jul 13, 2016 at 2:49 AM, Bjrnar Ness <bjornar(dot)ness(at)gmail(dot)com> wrote:
>> But with upsert/do nothing, this will not work as "needed".
>>
>> Would it be possible to introduce a "ON CONFLICT SELECT" argument:
>>
>> with _foo as (
>> insert into foo(i) values(1)
>> on conflict select returning id
>> ) insert into bar(foo_id,i)
>> select id,2 from _foo;

> I gather that the point of this pseudo SQL is to show how you might be
> able to project and select the values not successfully inserted. Can't
> you just pipeline together some CTEs instead?

What's "needed" seems a little ill-defined here, anyway. Would the SELECT
be expected to return values from the failed-to-be-inserted row, or from
the existing conflicting row? (Is there certain to be only one
conflicting row? With exclusion constraints I'd think not.)

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2016-07-13 17:18:27 Re: rethinking dense_alloc (HashJoin) as a memory context
Previous Message Tom Lane 2016-07-13 17:07:39 Re: application_name in process name?