Postgres 没有来自链接值为空的链接表的结果

Postgres no results from linked tables where linked values are null

我有这个查询:

update CA_San_Francisco as p 
set geo = u.geo 
from parcels_union u 
where u.street_number = p.street_number 
    and u.street_name = p.street_name 
    and u.street_type = p.street_type 
    and u.street_direction = p.street_direction 
    and u.street_unit = p.street_unit

但是它不会更新两个字段都为空的任何行。换句话说,如果两个表的 street_direction 中都没有值,即使它们相同 - 都是空值,我也得不到结果。

我知道某些东西不能 = Null。那么如何获得所有结果?

谢谢,布拉德

您可以检查该字段是否为 NULL,如果是,则将其更改为您可以检查的内容。

例如,您可以将 Where 子句更改为以下内容

where coalesce(u.street_number,'') = coalesce(p.street_number,'')
    and coalesce(u.street_name,'') = coalesce(p.street_name,'') 
    and coalesce(u.street_type,'') = coalesce(p.street_type,'') 
    and coalesce(u.street_direction,'') = coalesce(p.street_direction,'') 
    and coalesce(u.street_unit,'') = coalesce(p.street_unit,'')

但是如果这些列中有多行 NULL 那么您将在更新中得到意想不到的分配...