Data Cleaning Patterns
Normalize Text
Trim and Lowercase
Cleaning text often means removing extra whitespace and using a consistent case before comparison.
Program
Play the script to choose an email domain and return normalized matching addresses.
normalize_email_text.sql
CREATE TABLE raw_contacts (id INTEGER, email TEXT);
INSERT INTO raw_contacts VALUES (1, ' ADA@Example.com '), (2, 'lin@work.com'), (3, ' NIA@example.COM');
WITH params(domain_filter) AS (VALUES ()) SELECT id, lower(trim(email)) AS normalized_email FROM raw_contacts WHERE lower(trim(email)) LIKE '%' || (SELECT domain_filter FROM params) ORDER BY id;
CREATE TABLE raw_contacts (id INTEGER, email TEXT);
INSERT INTO raw_contacts VALUES (1, ' ADA@Example.com '), (2, 'lin@work.com'), (3, ' NIA@example.COM');
WITH params(domain_filter) AS (VALUES ()) SELECT id, lower(trim(email)) AS normalized_email FROM raw_contacts WHERE lower(trim(email)) LIKE '%' || (SELECT domain_filter FROM params) ORDER BY id;
trim
`trim(email)` removes leading and trailing spaces.
lowercase
`lower(...)` gives text a consistent comparison form.
cleaning filter
The selector changes the normalized domain filter without changing the cleaning expression.