From a83aa16f92396ba1802d84ceb9cec37f1f7178e3 Mon Sep 17 00:00:00 2001 From: Christopher Lenke <christopher.lenke@uni-bielefeld.de> Date: Mon, 23 Sep 2024 18:37:59 +0200 Subject: [PATCH] 23.09.2024 --- Procedures/exclude_ii_pg.txt | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Procedures/exclude_ii_pg.txt diff --git a/Procedures/exclude_ii_pg.txt b/Procedures/exclude_ii_pg.txt new file mode 100644 index 0000000..f4a25eb --- /dev/null +++ b/Procedures/exclude_ii_pg.txt @@ -0,0 +1,41 @@ +-- DROP PROCEDURE schema_xyz.exclude_ii_pg(text); + +CREATE OR REPLACE PROCEDURE schema_xyz.exclude_ii_pg(input_table text) + LANGUAGE plpgsql +AS $procedure$ + BEGIN + +DECLARE + +ec cursor is SELECT epid, uid_, pattern_nf, pattern_city from schema_xyz.exclude_pattern; +/* exclude things are deleted and a table _ex is created to save the excude results. input table must contain adr_id and top. +*/ + exclude_pattern RECORD; + +BEGIN + +EXECUTE 'alter table '||input_table||' add column exclude bigint, add column exclude_id bigint'; + +for exclude_pattern in ec + + LOOP + + EXECUTE 'update '||input_table||' set exclude=1, exclude_id='||exclude_pattern.epid|| ' + where ( + top='||exclude_pattern.uid_||' + and adr_id in (select adr_id from schema_xyz.result_II where + upper(address_full) like '''||exclude_pattern.pattern_nf||''' and (city is null or upper(city) like '''||exclude_pattern.pattern_city||''')))'; + + END LOOP; + + +EXECUTE 'drop table if exists '||input_table||'_ex'; +EXECUTE 'create table '||input_table||'_ex as (select * from '||input_table||')'; + +EXECUTE 'delete from '||input_table||' where exclude=1'; +commit; + +END; + END; +$procedure$ +; -- GitLab