在Postresql中进行更新时,列不明确

时间:2016-07-13 21:36:14

标签: postgresql sql-update updates

如果bx_temp中的min_failed小于表中当前的min_failed值,我正在尝试更新表。

我一直得到一个" min_failed是不明确的"在我的case语句中引用min_failed。我不能为它分配一个表别名。

<messageModal trigger="whatever here"></messageModal>

1 个答案:

答案 0 :(得分:2)

我无法测试查询,但您可以像这样修改它:

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;