Skip to content

Instantly share code, notes, and snippets.

@crossaidi
Last active December 25, 2015 03:59
Show Gist options
  • Save crossaidi/6913385 to your computer and use it in GitHub Desktop.
Save crossaidi/6913385 to your computer and use it in GitHub Desktop.
DELETE FROM table WHERE id IN
(SELECT UNNEST(STRING_TO_ARRAY(SUBSTRING(STRING_AGG(id::varchar, ','),
POSITION(',' in string_agg(id::varchar, ',')) + 1 ), ','))::integer
FROM table
GROUP BY field1, field2, field3, field4, field5, field6
HAVING COUNT(*) > 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment