pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christophe Pettus <xof@thebuild.com>
To: Barry Kimelman <blkimelman@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: problem with on conflict / do update using psql 14.4
Date: Sat, 24 Sep 2022 08:43:22 -0700
Message-ID: <FD75AF4B-D503-4B1A-BA13-BE5E4FA9CB7E@thebuild.com> (raw)
In-Reply-To: <CAMPa0rX0bLAJGh14X=g+LL5VoX1_16-pbFPeVFmKJKyv=Kz3bA@mail.gmail.com>
References: <CAMPa0rUQUqiVPQLdYSg7g8mrxyRzKf6cVjt2KXvJMnhvLcHbig@mail.gmail.com>
	<CAKE1AiaMhqwdpHuUCv+vx+1j7WYGne=kDyCFvLPMRATSNCN2vg@mail.gmail.com>
	<CAMPa0rUkyaFZnNZ-ZYQPz0S5rDEn8x7Onkg6=mG6szf__b0chw@mail.gmail.com>
	<65C8502E-7C7F-4F4D-B24B-708284C145F8@thebuild.com>
	<CAMPa0rX0bLAJGh14X=g+LL5VoX1_16-pbFPeVFmKJKyv=Kz3bA@mail.gmail.com>



> On Sep 24, 2022, at 08:29, Barry Kimelman <blkimelman@gmail.com> wrote:
> Thanks for the response. When I ran the INSERT with your suggested change I got an error message telling me
> "column reference 'company_name' is ambiguous"

As previously noted, you'll need to do both: add "excluded." to qualify the column names in the UPDATE.  Here's a contrived example:

xof=# create table t(i integer, j integer, k integer);
CREATE TABLE
xof=# create unique index on t(i) where j != 0;
CREATE INDEX
xof=# insert into t(i, j, k) values(1, 2, 3) on conflict (i) do update set k=k+1;
ERROR:  column reference "k" is ambiguous
LINE 1: ..., j, k) values(1, 2, 3) on conflict (i) do update set k=k+1;
xof=# insert into t(i, j, k) values(1, 2, 3) on conflict (i) do update set k=excluded.k+1;
ERROR:  there is no unique or exclusion constraint matching the ON CONFLICT specification
xof=# insert into t(i, j, k) values(1, 2, 3) on conflict (i) where j != 0 do update set k=excluded.k+1;
INSERT 0 1






view thread (14+ messages)  latest in thread

Message-ID: <FD75AF4B-D503-4B1A-BA13-BE5E4FA9CB7E@thebuild.com>
Permalink:  ../FD75AF4B-D503-4B1A-BA13-BE5E4FA9CB7E@thebuild.com/
Also on:    postgresql.org/message-id/FD75AF4B-D503-4B1A-BA13-BE5E4FA9CB7E@thebuild.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: xof@thebuild.com, blkimelman@gmail.com
  Subject: Re: problem with on conflict / do update using psql 14.4
  In-Reply-To: <FD75AF4B-D503-4B1A-BA13-BE5E4FA9CB7E@thebuild.com>
  References: <CAMPa0rUQUqiVPQLdYSg7g8mrxyRzKf6cVjt2KXvJMnhvLcHbig@mail.gmail.com> <CAKE1AiaMhqwdpHuUCv+vx+1j7WYGne=kDyCFvLPMRATSNCN2vg@mail.gmail.com> <CAMPa0rUkyaFZnNZ-ZYQPz0S5rDEn8x7Onkg6=mG6szf__b0chw@mail.gmail.com> <65C8502E-7C7F-4F4D-B24B-708284C145F8@thebuild.com> <CAMPa0rX0bLAJGh14X=g+LL5VoX1_16-pbFPeVFmKJKyv=Kz3bA@mail.gmail.com> <FD75AF4B-D503-4B1A-BA13-BE5E4FA9CB7E@thebuild.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox