insert into tmp.tmp_upd_personcard_lpuregion 
select c.personcardstate_id, c.personcard_id, tmp.get_lpuregion_id(c.lpu_id,c.lpuregiontype_id,c.person_id) lpuregion_id, c.person_id
from personcardstate c
join personstate p on p.person_id = c.person_id
where c.lpuregion_id is null and c.lpuregiontype_id in (1, 2)
and p.uaddress_id is not null and p.paddress_id is null
and not exists(select 1 from tmp.tmp_upd_personcard_lpuregion t where t.personcardstate_id = c.personcardstate_id)
limit 50000




