Re: doc: Clarify what "excluded" represents for INSERT ON CONFLICT - Mailing list pgsql-hackers

From Peter Geoghegan
Subject Re: doc: Clarify what "excluded" represents for INSERT ON CONFLICT
Date
Msg-id CAH2-Wzmx5Q-fakiieGOmv=bvOV_KTA1ObA-OZXVN5N6mc3Se3Q@mail.gmail.com
Whole thread Raw
In response to Re: doc: Clarify what "excluded" represents for INSERT ON CONFLICT  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: doc: Clarify what "excluded" represents for INSERT ON CONFLICT
List pgsql-hackers
On Thu, Jun 30, 2022 at 2:07 PM David G. Johnston
<david.g.johnston@gmail.com> wrote:
> Current:
> "The SET and WHERE clauses in ON CONFLICT DO UPDATE have access to the
> existing row using the table's name (or an alias), and to [rows] proposed
> for insertion using the special excluded table."
>
> The word table in that sentence is wrong and not a useful way to think of the thing which we've named excluded.  It
isa single value of a composite type having the structure of the named table.
 

I think that your reasoning is correct, but I don't agree with your
conclusion. The term "special excluded table" is a fudge, but that
isn't necessarily a bad thing. Sure, we could add something about the
UPDATE being similar to an UPDATE with a self-join, as I said
upthread. But I think that that would make the concept harder to
grasp.

> I'll agree that most people will mentally paper over the difference and go merrily on their way.  At least one person
recentlydid not do that, which prompted an email to the community
 

Can you provide a reference for this? Didn't see anything like that in
the reference you gave upthread.

I have a hard time imagining a user that reads the INSERT docs and
imagines that "excluded" is a relation that is visible to the query in
ways that are not limited to expression evaluation for the UPDATE's
WHERE/SET. The way that it works (and doesn't work) follows naturally
from what a user would want to do in order to upsert. MySQL's INSERT
... ON DUPLICATE KEY UPDATE feature has a magical UPSERT-only
expression instead of "excluded".

-- 
Peter Geoghegan



pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: doc: Clarify what "excluded" represents for INSERT ON CONFLICT
Next
From: "David G. Johnston"
Date:
Subject: Re: doc: Clarify what "excluded" represents for INSERT ON CONFLICT