do $$
declare
_r record;
i integer;
BEGIN
i := 1;
for _r in 
(
select t.*, c.lpu_id,c.lpuregiontype_id,c.person_id
from tmp.tmp_upd_personcard_lpuregion t
join personcardstate c on c.personcardstate_id = t.personcardstate_id
where t.lpuregion_id is null
and t.isload = 0
--and t.personcardstate_id = 520101001828009
--and c.lpu_id = 2874
limit 70000
)
loop
raise notice '%', _r.personcardstate_id;
update tmp.tmp_upd_personcard_lpuregion set lpuregion_id = tmp.get_lpuregion_id(_r.lpu_id,_r.lpuregiontype_id,_r.person_id) where personcardstate_id = _r.personcardstate_id;
update tmp.tmp_upd_personcard_lpuregion set isload = 1 where personcardstate_id = _r.personcardstate_id;
end loop;
end $$;


