Submitted on: 03-16-2001
Description:
Delete duplicate records in a table
Code:
This is a fast way to find duplicate records in a table and delete them.
Note: Replace the various table and field names with yours.
Example:
--
-- Create a function which will return the max OID from a table
-- based on the unique id. In this case, it is hash
--
create function maxoidhash( int8)
returns int as
'select max(oid) from codes where hash = $1'
language 'sql';
--
-- Now delete
--
delete from codes where oid < maxoidhash(hash) ;
--
-- Drop the function
--
drop function maxoidhash;
|