我有两个 Postgres 表:
表一
CREATE TABLE tmp.pm_update_20230101 (
fid varchar NULL,
fecha date NULL,
p float4 NULL
);
表 2
CREATE TABLE aemet.pmes (
indic varchar NOT NULL,
fecha date NOT NULL,
prec float4 NULL,
CONSTRAINT pmes_pkey PRIMARY KEY (indic, fecha)
);
我想用表 2 中的一些行插入或更新表 1 中的行,但是在下面的语句中我不知道在 excluded.COLUMN 中我应该写 excluded.p 还是 excluded.prec
insert into aemet.pmes (indic , fecha, prec)
select t.fid , t.fecha , t.p
from tmp.pm_update_20230101 t
where p is not null
on conflict on constraint pmes_pkey
do update set prec = excluded. COLUMN ;