【发布时间】:2016-07-25 07:13:32
【问题描述】:
以下是我的 SQL 查询:
update table
set unit_id = T1.unit_id_temp from
(select case when unit_id4 is not null then unit_id4
when unit_id3 is not null then unit_id3
when unit_id2 is not null then unit_id2
when unit_id1 is not null then unit_id1
else unit_id
end as unit_id_temp,
unit_id1,unit_id2,unit_id3,unit_id4
from table) T1
where table.unit_id4 = T1.unit_id4
and table.unit_id3 = T1.unit_id3
and table.unit_id2 = T1.unit_id2
and table.unit_id1 = T1.unit_id1
从上面的查询中,当它们为 NULL 时,我无法比较列,因为条件返回 false。
例如: 当 unit_id4 为 null 时, table.unit_id4 = T1.unit_id4 返回 False。
因此,只要任一列包含 NULL 值,我的更新就会失败。
我试过用不区分,它不起作用。抛出以下错误:
更新 - 0 行,0.000 秒] [代码:0,SQL 状态:42601] 错误:“不同”处或附近的语法错误
【问题讨论】:
标签: postgresql amazon-redshift