Re: Deleting one of 2 identical records

From: Andy Colson <andy(at)squeakycode(dot)net>
To: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Deleting one of 2 identical records
Date: 2011-09-06 17:52:08
Message-ID: 4E665DC8.6010104@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2011-09-06 17:54:45 Re: Deleting one of 2 identical records
Previous Message Thom Brown 2011-09-06 17:44:43 Re: Deleting one of 2 identical records