Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- DROP FUNCTION schema_xyz.city_cleaning_pg(text);
CREATE OR REPLACE FUNCTION schema_xyz.city_cleaning_pg(spalte_in text)
RETURNS character varying
LANGUAGE plpgsql
AS $function$
DECLARE
ergebnis varchar;
city_cleaned varchar;
BEGIN
city_cleaned:=regexp_replace(upper(spalte_in),'D?E?O?W?-? ?[0-9]{4,6} ?',' ' , 'g');
city_cleaned:=regexp_replace(city_cleaned,'D?E?O?W?-? ?[0-9]{2,2} [0-9]{3,3} ?',' ' , 'g');
city_cleaned:=regexp_replace(city_cleaned,'D?E?o?W?-? ?[0-9]{3,3} [0-9]{2,2} ?',' ' , 'g');
city_cleaned:=ltrim(rtrim(city_cleaned));
city_cleaned:=replace(city_cleaned,', ', ' ');
city_cleaned:=replace(city_cleaned,' ', ' ');
city_cleaned:=replace(city_cleaned,' ', ' ');
if (city_cleaned like '%,')
then
city_cleaned:=substr(city_cleaned, 1, length(city_cleaned)-1);
end if;
city_cleaned:=ltrim(rtrim(city_cleaned));
city_cleaned:=regexp_replace(city_cleaned,'^[0-9]{1,3} ',' ' , 'g');
city_cleaned:=regexp_replace(city_cleaned,' [0-9]{1,3}$',' ' , 'g');
city_cleaned:=regexp_replace(city_cleaned,' [0-9]{1,3} ',' ' , 'g');
city_cleaned:=replace(city_cleaned,', ', ' ');
city_cleaned:=replace(city_cleaned,' ', ' ');
city_cleaned:=replace(city_cleaned,' ', ' ');
city_cleaned:=ltrim(rtrim(city_cleaned));
ergebnis:=city_cleaned;
RETURN ergebnis;
END;
$function$
;