oppijanumerorekisteri
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
hetu_run_anonymizer()
Parameters
Name
Type
Mode
IN
Definition
declare broken record; declare rowcount integer; declare new_hetu text; BEGIN rowcount := 0; for broken in (select * from henkilo where (hetu like '%-%' and hetu not like '%-9%') or (query_hetu like '%-%' and query_hetu not like '%-9%')) LOOP LOOP -- detect duplicates stupidly: loop the update until there is no unique_violation BEGIN select random_hetu() into new_hetu; raise notice 'Trying to replace "%" and "%" with "%"', broken.hetu, broken.query_hetu, new_hetu; update henkilo set (hetu, query_hetu) = (new_hetu, new_hetu) where id = broken.id; rowcount := rowcount+1; EXIT; -- successful update, exit the inner loop EXCEPTION WHEN unique_violation THEN -- got a dup from the random_hetu. do nothing, the loop will cause a retry END; END LOOP; END LOOP; return rowcount; END;