EasyString Functions
Extract domain from email addresses
The query
SQL
SELECT
email,
SPLIT_PART(email, '@', 2) AS domain,
SPLIT_PART(SPLIT_PART(email, '@', 2), '.', -1) AS tld
FROM customers
WHERE email IS NOT NULL;Note
“SPLIT_PART with -1 as position returns last segment (PostgreSQL 14+). For older versions, use multiple SPLIT_PARTs.