Re: remote duplicate rows

From: Berend Tober <btober(at)seaworthysys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: remote duplicate rows
Date: 2006-09-14 12:38:17
Message-ID: 45094D39.5040407@seaworthysys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

A. Kretschmer wrote:

>am Wed, dem 13.09.2006, um 15:46:58 -0700 mailte Junkone folgendes:
>
>
>>hI
>>i have a bad situation that i did not have primary key. so i have a
>>table like this
>>colname1 colname2
>>1 apple
>>1 apple
>>2 orange
>>2 orange
>>
>>It is a very large table. how do i remove the duplctes quickly annd
>>without much change.
>>
>>
>
>begin;
>alter table foo rename to tmp;
>create table foo as select distinct * from tmp;
>commit;
>
>
A couple potential problems here. First, you forgot to drop table tmp. But maybe that is good thing because although the OP hasn't told us anything else useful about the situation, and he has clearly contrived a simplistic facsimile of his real problem, to be useful the table most likely either has foreign key references, and/or is the primary key for other table foreign keys. You're suggestion will break whatever application this data base supports because all the foreign keys will point to table tmp rather than foo afterwards. Similarly, there is the problem of any indexes on the table that would be lost. But I suppose one can make the point that your suggestion is a great solution, given the contrived example and insufficient problem understanding presented by the OP -- I really think he needs more help than he realizes.

Regards,
Berend Tober

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jan van der Weijde 2006-09-14 13:18:37 Question about timestamp with time zone
Previous Message Florian Weimer 2006-09-14 12:26:10 Inherited tables vs UNION ALL views