diff options
Diffstat (limited to 'graphs/sql/corrupted_friends')
| -rw-r--r-- | graphs/sql/corrupted_friends/req01.sql | 18 | ||||
| -rw-r--r-- | graphs/sql/corrupted_friends/req02.sql | 41 | ||||
| -rw-r--r-- | graphs/sql/corrupted_friends/req03.sql | 2 |
3 files changed, 61 insertions, 0 deletions
diff --git a/graphs/sql/corrupted_friends/req01.sql b/graphs/sql/corrupted_friends/req01.sql new file mode 100644 index 0000000..bc759f7 --- /dev/null +++ b/graphs/sql/corrupted_friends/req01.sql @@ -0,0 +1,18 @@ +CREATE TYPE public.prefix AS ENUM ( + 'MRS', + 'MS', + 'MR', + 'DR' +); + +CREATE TABLE dtf.madelines_contacts +( + id INTEGER PRIMARY KEY, + title public.prefix, + first_name TEXT, + last_name TEXT, + phone TEXT, + email TEXT, + favorite BOOLEAN, + created_at TIMESTAMP +); diff --git a/graphs/sql/corrupted_friends/req02.sql b/graphs/sql/corrupted_friends/req02.sql new file mode 100644 index 0000000..11f9947 --- /dev/null +++ b/graphs/sql/corrupted_friends/req02.sql @@ -0,0 +1,41 @@ +INSERT INTO dtf.madelines_contacts +SELECT +id, +upper(split_part(regexp_replace(trim(full_name), '([^[[:ascii:]]]*)|([[:digit:]]*)', '', 'g'), ' ', 1))::public.prefix AS title, +initcap(split_part(regexp_replace(trim(full_name), '([^[[:ascii:]]]*)|([[:digit:]]*)', '', 'g'), ' ', 2)) AS first_name, +initcap(split_part(regexp_replace(trim(full_name), '([^[[:ascii:]]]*)|([[:digit:]]*)', '', 'g'), ' ', 3)) AS last_name, +concat( + lpad( + regexp_replace( + regexp_replace(phone, '[^0-9\.\-]', '', 'g'), + '(.?.?.?)[\.\-].*', + '\1', + 'g' + ), + 3, '0' + ), + '.', + lpad( + regexp_replace( + regexp_replace(phone, '[^0-9\.\-]', '', 'g'), + '.*[\.\-](.?.?.?)[\.\-].*', + '\1', + 'g' + ), + 3, '0' + ), + '.', + lpad( + regexp_replace( + regexp_replace(phone, '[^0-9\.\-]', '', 'g'), + '.*[\.\-](.?.?.?)', + '\1', + 'g' + ), + 3, '0' + ) +) AS phone, +regexp_replace(trim(email), '[^[[:ascii:]]]', '', 'g') AS email, +trim(favorite) LIKE '1' AS favorite, +created_at::timestamp AS created_at +FROM dtf.madelines_contacts_corrupted AS c diff --git a/graphs/sql/corrupted_friends/req03.sql b/graphs/sql/corrupted_friends/req03.sql new file mode 100644 index 0000000..baa5863 --- /dev/null +++ b/graphs/sql/corrupted_friends/req03.sql @@ -0,0 +1,2 @@ +UPDATE dtf.madelines_contacts +SET email = concat(lower(first_name), '.', lower(last_name),'@roger_roger.com'); |
