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

Поиск
Список
Период
Сортировка
От Barry Kimelman
Тема Re: problem with on conflict / do update using psql 14.4
Дата
Msg-id CAMPa0rVHkdFe8_bog6Pt9Oa=7_LQkGDbR49sA_a043mE37G6dA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: problem with on conflict / do update using psql 14.4  (Christophe Pettus <xof@thebuild.com>)
Ответы Re: problem with on conflict / do update using psql 14.4  (Christophe Pettus <xof@thebuild.com>)
Re: problem with on conflict / do update using psql 14.4  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general

On Sat, Sep 24, 2022 at 10:44 AM Christophe Pettus <xof@thebuild.com> wrote:


> 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


I added the excluded reference as you stated. I ran the INSERT and I did indeed get back a response of "INSERT  0 1"
However, when I ran a select to look at the table, nothing had been inserted.
I thought the whole point of ON CONFLICT DO UPDATE was so that you could modify the data so that it would be inserted

В списке pgsql-general по дате отправления:

Предыдущее
От: Christophe Pettus
Дата:
Сообщение: Re: problem with on conflict / do update using psql 14.4
Следующее
От: Christophe Pettus
Дата:
Сообщение: Re: problem with on conflict / do update using psql 14.4