-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprop_name.sql
69 lines (69 loc) · 2.48 KB
/
prop_name.sql
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- Need to fix names with a de such as Van de Vars and Colonel de Vars
create or replace function prop_name(fullname varchar) RETURNS varchar AS $$
DECLARE
r varchar;
BEGIN
fullname := initcap(fullname);
CASE
WHEN fullname like 'FS %' THEN
r = REGEXP_REPLACE(fullname,'^Fs ','FS ');
WHEN fullname like 'MCA%' THEN
r = REGEXP_REPLACE(fullname,'^Mca','McA');
WHEN fullname like 'MCB%' THEN
r = REGEXP_REPLACE(fullname,'^Mcb','McB');
WHEN fullname like 'MCC%' THEN
r = REGEXP_REPLACE(fullname,'^Mcc','McC');
WHEN fullname like 'MCD%' THEN
r = REGEXP_REPLACE(fullname,'^Mcd','McD');
WHEN fullname like 'MCE%' THEN
r = REGEXP_REPLACE(fullname,'^Mce','McE');
WHEN fullname like 'MCF%' THEN
r = REGEXP_REPLACE(fullname,'^Mcf','McF');
WHEN fullname like 'MCG%' THEN
r = REGEXP_REPLACE(fullname,'^Mcg','McG');
WHEN fullname like 'MCH%' THEN
r = REGEXP_REPLACE(fullname,'^Mch','McH');
WHEN fullname like 'MCI%' THEN
r = REGEXP_REPLACE(fullname,'^Mci','McI');
WHEN fullname like 'MCJ%' THEN
r = REGEXP_REPLACE(fullname,'^Mcj','McJ');
WHEN fullname like 'MCK%' THEN
r = REGEXP_REPLACE(fullname,'^Mck','McK');
WHEN fullname like 'MCL%' THEN
r = REGEXP_REPLACE(fullname,'^Mcl','McL');
WHEN fullname like 'MCM%' THEN
r = REGEXP_REPLACE(fullname,'^Mcm','McM');
WHEN fullname like 'MCN%' THEN
r = REGEXP_REPLACE(fullname,'^Mcn','McN');
WHEN fullname like 'MCO%' THEN
r = REGEXP_REPLACE(fullname,'^Mco','McO');
WHEN fullname like 'MCP%' THEN
r = REGEXP_REPLACE(fullname,'^Mcp','McP');
WHEN fullname like 'MCQ%' THEN
r = REGEXP_REPLACE(fullname,'^Mcq','McQ');
WHEN fullname like 'MCR%' THEN
r = REGEXP_REPLACE(fullname,'^Mcr','McR');
WHEN fullname like 'MCS%' THEN
r = REGEXP_REPLACE(fullname,'^Mcs','McS');
WHEN fullname like 'MCT%' THEN
r = REGEXP_REPLACE(fullname,'^Mct','McT');
WHEN fullname like 'MCU%' THEN
r = REGEXP_REPLACE(fullname,'^Mcu','McU');
WHEN fullname like 'MCV%' THEN
r = REGEXP_REPLACE(fullname,'^Mcv','McV');
WHEN fullname like 'MCW%' THEN
r = REGEXP_REPLACE(fullname,'^Mcw','McW');
WHEN fullname like 'MCX%' THEN
r = REGEXP_REPLACE(fullname,'^Mcx','McX');
WHEN fullname like 'MCY%' THEN
r = REGEXP_REPLACE(fullname,'^Mcy','McY');
WHEN fullname like 'MCZ%' THEN
r = REGEXP_REPLACE(fullname,'^Mcz','McZ');
WHEN fullname like '% DE %' THEN
r = REGEXP_REPLACE(fullname,'^ De ',' de ');
ELSE
r = initcap(fullname);
END CASE;
RETURN r;
END;
$$ LANGUAGE plpgsql;