在postgres中我们可以通过关联查询另外一张表来关联当前表的数据:

1
2
3
4
5
update 待更新表 a
set 待更新表_字段一 = b.字段一 ,
待更新表_字段二 = b.字段二
from 关联表 b
where a.关联字段= b.关联字段

1
2
3
4
update test001 a 
set name= b.name,age=b.age
from test002 b
where a.id= b.id