postgresql multi-table joint batch update

update table_p as p
set p_name = a.name,p_user = a.user_id,p_type = 'P02'
from (
select x.user_id,x.name,x.p_id from table_u x
join table_p y on x.p_id = y.p_id
) as a where p.p_id = a.p_id;

ps: I tried several ways to write it, I feel this is more appropriate

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325428647&siteId=291194637