Skip to content

Instantly share code, notes, and snippets.

@jkatz
Created August 20, 2013 17:39
Show Gist options
  • Save jkatz/6284672 to your computer and use it in GitHub Desktop.
Save jkatz/6284672 to your computer and use it in GitHub Desktop.
WITH emails AS (
SELECT e.id, split_part(e.email, '@', 1) || row_number() OVER (PARTITION BY split_part(e.email, '@', 1)) AS email
FROM email_addresses e
WHERE e.email !~ '@(domain|example).com$' AND e.email <> ''
)
UPDATE email_addresses e
SET email = emails.email || '@example.com'
FROM emails
WHERE e.id = emails.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment