在 Postgresql 中进行更新时列不明确
Column is ambiguous when doing an update in Postresql
如果 bx_temp 中的 min_failed 小于 table 中的当前 min_failed 值,我正在尝试更新 table。
我不断收到 "min_failed is ambiguous" 指的是我的案例陈述中的 min_failed。不过我也不能给它分配一个 table 别名。
with c as (select * from b_temp)
update table b
set min_failed = (select case when ct.min_failed < min_failed then ct.min_failed else min_failed end)
from c
where c.user = b.user
我无法测试查询,但您可以这样修改它:
WITH c AS (SELECT * FROM b_temp)
UPDATE table b
SET min_failed = LEAST(c.min_failed,b.min_failed)
-- Use LEAST() instead of case logic. Also fixes your error because you were using SELECT without a FROM
FROM c
WHERE c.user = b.user;
如果 bx_temp 中的 min_failed 小于 table 中的当前 min_failed 值,我正在尝试更新 table。
我不断收到 "min_failed is ambiguous" 指的是我的案例陈述中的 min_failed。不过我也不能给它分配一个 table 别名。
with c as (select * from b_temp)
update table b
set min_failed = (select case when ct.min_failed < min_failed then ct.min_failed else min_failed end)
from c
where c.user = b.user
我无法测试查询,但您可以这样修改它:
WITH c AS (SELECT * FROM b_temp)
UPDATE table b
SET min_failed = LEAST(c.min_failed,b.min_failed)
-- Use LEAST() instead of case logic. Also fixes your error because you were using SELECT without a FROM
FROM c
WHERE c.user = b.user;