Re: INSERT ... ON CONFLICT syntax issues

From: Peter Geoghegan <pg(at)heroku(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Andres Freund <andres(at)anarazel(dot)de>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Subject: Re: INSERT ... ON CONFLICT syntax issues
Date: 2015-05-04 22:54:58
Message-ID: CAM3SWZRnHp_W5e+zhB+WWRy0TZCVSKAvATe4Tc4qVPSy1BvVFg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Apr 29, 2015 at 12:09 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> * Don't change the names of the pseudo-alias EXCLUDED.* (or the alias
>> TARGET.*). Those seem fine to me as well.
>
> There seem to be a few votes for NEW and OLD. That's what I proposed
> originally, and (surprise, surprise) I still like that better too.

That makes the following valid:

INSERT INTO distributors (did, dname)
VALUES (5, 'Gizmo transglobal')
ON CONFLICT (did) DO UPDATE SET dname = NEW.dname
RETURNING OLD.dname;

So you're projecting "OLD.dname" from RETURNING, here -- so "OLD"
refers to the row added back to the relation on update (or perhaps the
row simply inserted). That's pretty bad. I really don't want to add a
kludge to make the target relation have an alias in one context but
not in the other.

--
Peter Geoghegan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message mark 2015-05-04 23:35:37 Re: [GENERAL] Insert result does not match record count
Previous Message David Fetter 2015-05-04 21:42:56 tzdata and 9.4.2, etc.