Re: problem with on conflict / do update using psql 14.4

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: Barry Kimelman <blkimelman(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: problem with on conflict / do update using psql 14.4
Date: 2022-09-24 15:43:22
Message-ID: FD75AF4B-D503-4B1A-BA13-BE5E4FA9CB7E@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Sep 24, 2022, at 08:29, Barry Kimelman <blkimelman(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Barry Kimelman 2022-09-24 15:49:09 Re: problem with on conflict / do update using psql 14.4
Previous Message Barry Kimelman 2022-09-24 15:29:11 Re: problem with on conflict / do update using psql 14.4