Postgres ON CONFLICT 设置列引用不明确

pio*_*rek 4 sql postgresql upsert

我有一张桌子:

create table c (
    e text not null,
    m text not null,
    p numeric not null,
    PRIMARY KEY (e, m)
);
Run Code Online (Sandbox Code Playgroud)

我想做插入或更新以增加p现有值:

insert into c values (...) on conflict (e, m) do update set
            p = p + excluded.p
Run Code Online (Sandbox Code Playgroud)

我得到一个错误:

错误:列引用“p”不明确

它是如何模棱两可的?我应该如何编写我的插入内容以添加excluded.p到已经存在的值中?

Gor*_*off 5

好吧,你可能想要:

        p = c.p + excluded.p
Run Code Online (Sandbox Code Playgroud)

您可能想要:

        p = excluded.p + excluded.p
Run Code Online (Sandbox Code Playgroud)

您需要指定。