Skip to content

Instantly share code, notes, and snippets.

@joshkoenig
Created April 8, 2017 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshkoenig/d45617272b231f375064c79caefd701e to your computer and use it in GitHub Desktop.
Save joshkoenig/d45617272b231f375064c79caefd701e to your computer and use it in GitHub Desktop.
Wipe out dupe accounts - next ETL will fill in the valid ones from SFDC
# Cleanup Accounts and Contacts
CREATE TEMPORARY TABLE account_cleanup_temp SELECT organization_uuid FROM _accounts_ WHERE organization_uuid IS NOT NULL GROUP BY organization_uuid HAVING COUNT(*) > 1;
DELETE a FROM _accounts_ INNER JOIN account_cleanup_temp t ON a.organization_uuid = t.organization_uuid;
DROP TABLE account_cleanup_temp;
CREATE TEMPORARY TABLE contact_cleanup_temp SELECT user_uuid FROM _contacts_ WHERE user_uuid IS NOT NULL GROUP BY user_uuid HAVING COUNT(*) > 1;
DELETE c FROM _contacts_ c INNER JOIN contact_cleanup_temp t ON c.user_uuid = t.user_uuid;
DROP TABLE contact_cleanup_temp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment