Re: [HACKERS] INSERT ... ON CONFLICT () SELECT - Mailing list pgsql-hackers

From Peter Geoghegan
Subject Re: [HACKERS] INSERT ... ON CONFLICT () SELECT
Date
Msg-id CAH2-Wz=NZEe4T_b99ShodvS0h9Nigz5fZDpC5jXU8Zjt0446Tw@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] INSERT ... ON CONFLICT () SELECT  (Matt Pulver <mpulver@unitytechgroup.com>)
Responses Re: [HACKERS] INSERT ... ON CONFLICT () SELECT  (Matt Pulver <mpulver@unitytechgroup.com>)
List pgsql-hackers
On Sun, Jun 18, 2017 at 4:33 AM, Matt Pulver <mpulver@unitytechgroup.com> wrote:
> This would be nearly identical to the existing error message that is
> produced when running:
>
> INSERT INTO example (name) VALUES ('foo'), ('foo')
> ON CONFLICT (name) DO UPDATE SET value=1
> RETURNING *
>
>
> which gives the error message:
> "ERROR:  ON CONFLICT DO UPDATE command cannot affect row a second time
> HINT:  Ensure that no rows proposed for insertion within the same command
> have duplicate constrained values."

FWIW, the fact that ON CONFLICT DO UPDATE will never update a row that
it itself inserted has proved valuable. For example, transition
tables, which appeared within statement triggers, have no need to
consider the case where an inserted tuple appears for the INSERT
statement case, as well as the UPDATE statement case (in another
form).

> Technically, an error doesn't need to be produced for the above "ON CONFLICT
> DO SELECT" statement - I think it is still perfectly well-defined to return
> duplicate rows as in option 1.

Returning rows with duplicate values seems rather unorthodox.

-- 
Peter Geoghegan



pgsql-hackers by date:

Previous
From: Julien Rouhaud
Date:
Subject: Re: [HACKERS] Typo in drop_publication.sgml
Next
From: Alexander Korotkov
Date:
Subject: Re: [HACKERS] GSoC 2017: Foreign Key Arrays