Re: Deleting one of 2 identical records - Mailing list pgsql-general

From Andy Colson
Subject Re: Deleting one of 2 identical records
Date
Msg-id 4E665DC8.6010104@squeakycode.net
Whole thread Raw
In response to Deleting one of 2 identical records  ("Gauthier, Dave" <dave.gauthier@intel.com>)
List pgsql-general
On 9/6/2011 12:39 PM, Gauthier, Dave wrote:
> Hi:
>
> If I have a table that has 2 records which are identical with regard to
> all their column values, is there a way to delete one of them, leaving
> one remaining? Is there some unique record_id key of some sort I can use
> for somethign like this?
>
> Thanks in Advance!
>

Not easily that I know of.  I have two thoughts:

1)
create table junk (like orig);
insert into junk select distinct from orig;
delete from orig where exists(select from junk);
insert into orig select * from junk;

2)
alter table orig add uid integer;
create sequence bob;
update orig set uid = nextval('bob');
drop sequence bob;
-- magic to delet using uid

Ah, Thom just answered.  I like his better, but I'll post this just for
completeness...

-Andy

pgsql-general by date:

Previous
From: Thom Brown
Date:
Subject: Re: Deleting one of 2 identical records
Next
From: Andy Colson
Date:
Subject: Re: Deleting one of 2 identical records