diff --git a/Procedures/wostransfo_proc_pg_text__int8_.txt b/Procedures/wostransfo_proc_pg_text__int8_.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f5ad0a61a17afbcb68c55fd600a4fc5db2c9eaa --- /dev/null +++ b/Procedures/wostransfo_proc_pg_text__int8_.txt @@ -0,0 +1,46 @@ +-- DROP PROCEDURE schema_xyz.wostransfo_proc_pg(text, int8); + +CREATE OR REPLACE PROCEDURE schema_xyz.wostransfo_proc_pg(input_table text, art bigint) + LANGUAGE plpgsql +AS $procedure$ + BEGIN + +DECLARE + +/* Type=2: simple type: only wos_standard_plus Type=1: additionally insert wos_standard_plus_erg. Caution: takes a long time! (is not used) + +city_cleaning: remove postcodes (they may interfere because they are not available in the city field in WoS) */ +BEGIN + +/* Rename address_full to address_full_original in the input table and create a new column address_full */ + +EXECUTE 'alter table '||input_table||' rename column address_full to address_full_original'; +EXECUTE 'alter table '||input_table||' rename column city to city_original'; + +EXECUTE 'alter table '||input_table||' add address_full varchar'; +EXECUTE 'alter table '||input_table||' add city varchar'; + +execute 'ALTER TABLE '||input_table||' SET UNLOGGED'; + +if (art=1) THEN +EXECUTE 'update /*+ parallel(24) */ '||input_table||' set address_full=schema_xyz.wos_transformation_pg(address_full_original,1)'; +EXECUTE 'update /*+ parallel(24) */ '||input_table||' set city=schema_xyz.wos_transformation_pg(city_original,1)'; + +elsif (art=2) then +EXECUTE 'update /*+ parallel(24) */ '||input_table||' set address_full=schema_xyz.wos_transformation_pg(address_full_original,2)'; +commit; +EXECUTE 'update /*+ parallel(24) */ '||input_table||' set city=schema_xyz.wos_transformation_pg(city_original,2)'; +commit; + +END IF; + +if (art=1 or art=2) then +EXECUTE 'update /*+ parallel(24) */ '||input_table||' set city=schema_xyz.city_cleaning_pg(city)'; +commit; +end if; + +END; + + END; +$procedure$ +;