Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oc7KQ-0002ha-NK for pgsql-general@arkaria.postgresql.org; Sat, 24 Sep 2022 15:44:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oc7KP-00011W-81 for pgsql-general@arkaria.postgresql.org; Sat, 24 Sep 2022 15:44:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oc7KO-00010X-TR for pgsql-general@lists.postgresql.org; Sat, 24 Sep 2022 15:44:28 +0000 Received: from smtp101.iad3a.emailsrvr.com ([173.203.187.101]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oc7KL-00043S-Op for pgsql-general@lists.postgresql.org; Sat, 24 Sep 2022 15:44:27 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp5.relay.iad3a.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 9937723C28; Sat, 24 Sep 2022 11:44:23 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: problem with on conflict / do update using psql 14.4 From: Christophe Pettus In-Reply-To: Date: Sat, 24 Sep 2022 08:43:22 -0700 Cc: pgsql-general@lists.postgresql.org X-Mailbutler-Message-Id: 1CB9D763-4D1C-40F6-950F-A7D16D225071 Content-Transfer-Encoding: quoted-printable Message-Id: References: <65C8502E-7C7F-4F4D-B24B-708284C145F8@thebuild.com> To: Barry Kimelman X-Mailer: Apple Mail (2.3608.120.23.2.7) X-Classification-ID: bcc142e4-1b37-4155-bacb-2268342da3d7-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Sep 24, 2022, at 08:29, Barry Kimelman = 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=3D# create table t(i integer, j integer, k integer); CREATE TABLE xof=3D# create unique index on t(i) where j !=3D 0; CREATE INDEX xof=3D# insert into t(i, j, k) values(1, 2, 3) on conflict (i) do update = set k=3Dk+1; ERROR: column reference "k" is ambiguous LINE 1: ..., j, k) values(1, 2, 3) on conflict (i) do update set k=3Dk+1; xof=3D# insert into t(i, j, k) values(1, 2, 3) on conflict (i) do update = set k=3Dexcluded.k+1; ERROR: there is no unique or exclusion constraint matching the ON = CONFLICT specification xof=3D# insert into t(i, j, k) values(1, 2, 3) on conflict (i) where j = !=3D 0 do update set k=3Dexcluded.k+1; INSERT 0 1