Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres ON CONFLICT set column reference is ambiguous

I have a table:

create table c (
    e text not null,
    m text not null,
    p numeric not null,
    PRIMARY KEY (e, m)
);

and I want to do insert or update that adds p to existing value:

insert into c values (...) on conflict (e, m) do update set
            p = p + excluded.p

and i get an error:

ERROR: column reference "p" is ambiguous

how it's ambiguous? how should i write my insert to add excluded.p to the already existing value?

like image 348
piotrek Avatar asked Mar 25 '19 17:03

piotrek


1 Answers

Well, you probably want:

        p = c.p + excluded.p

It is possible that you want:

        p = excluded.p + excluded.p

You need to specify.

like image 144
Gordon Linoff Avatar answered Oct 25 '22 03:10

Gordon Linoff