DO
$do$
DECLARE
_rowPage int:=0;
_rowPageSize int:=100000;
_counter int:= (select count(1) from test t1 where coalesce(union_id,'')<>'');
BEGIN
WHILE _rowPage*_rowPageSize<_counter
loop
execute 'WITH temp_unionid_mapping AS ( SELECT mobile,union_id,remark FROM test where coalesce(union_id,'')<>''
ORDER BY mobile limit '||_rowPageSize||' OFFSET '||_rowPage * _rowPageSize ||')
UPDATE t_user SET union_id = t1.union_id,remark=t1.remark FROM temp_unionid_mapping t1
WHERE t1.mobile=t_user.mobile '
;
commit;
_rowPage := _rowPage + 1;
RAISE NOTICE 'The rowPage is %', _rowPage;
END LOOP;
END
$do$
pgsql在窗口内定义变量,批量更新
于 2023-06-14 17:46:36 首次发布