--select * into tmp.gpp_medstafffactcache_20220119 from medstafffactcache 
-- Те у кого только косячные  lpusection_id
do $$
declare
r_id bigint;
begin

	
	
	FOR r_id IN
		select id from persis.workplace --limit 100
			where id in (select medstafffact_id from medstafffactcache where lpusection_id not in (select lpusection_id from v_lpusection) )

	LOOP
	perform persis.p_WorkPlace_upd (workplace_id => r_id, isreload=>1);
	END LOOP;
end $$
