pg_normalize_email
Normalize email addresses in PostgreSQL
pg_normalize_email · Normalize email addresses in PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101230 | pg_normalize_email | pg_normalize_email | 1.0.9 | FUNC | PostgreSQL | SQL |
PostgreSQL · 12, 13, 14, 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
pg_normalize_email 1.0.9 provides one immutable normalization function for selected email providers. It lowercases addresses, maps one provider domain, and removes provider-specific dots or plus tags. Use it only when deliberate account-deduplication policy accepts the risk of treating distinct input strings as one identity.
Core Workflow
Function Behavior
normalize_email(text)requires exactly one at-sign and raises an exception for NULL or malformed splitting.- All input is lowercased, and googlemail.com is rewritten to gmail.com.
- For gmail.com and live.com, dots in the local part and the first plus suffix are removed.
- For ya.ru, hotmail.com, and outlook.com, only the first plus suffix is removed. Other domains are only lowercased.
Caveats
- The function is not a complete RFC email validator: it does not trim whitespace, validate nonempty parts, normalize internationalized domains, or account for quoted local parts.
- Provider behavior can change, and provider-specific normalization may merge addresses that an application considers distinct. Keep the original address and treat normalized uniqueness as an explicit product decision.
- Because the function is declared immutable, changing its rules later requires rebuilding dependent expression indexes and reviewing stored derived values.