Created
January 11, 2011 23:59
-
-
Save alchemycs/775417 to your computer and use it in GitHub Desktop.
Delete duplicate tuples from an entity that uses a pseudo primary key (eg, sequence/auto increment) instead of true keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Make a temporary table for unneeded PKs | |
create temporary table dirty_identifier (pseudo_key integer); | |
-- Get the PKs we don't need | |
insert into dirty_identifier ( | |
select dt1.pseudo_pk from dirty_table as dt1, dirty_table as dt2 where | |
dt1.true_pk_1 = dt2.true_pk_1 | |
-- and dt1.true_pk_2 = dt2.true_pk_3 | |
-- and ... keep repeating for however many attributes make your real key | |
and dt1.pseudo_pk > dt2.pseudo_pk | |
); | |
-- Finally delete the unneeded tuples from the dirty table | |
delete from dirty_table where pseudo_pk in (select pseudo_pk from dirty_identifier); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment