Re: Delete 1 Record of 2 Duplicate Records

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: greg(at)turnstep(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Delete 1 Record of 2 Duplicate Records
Date: 2003-01-31 01:16:26
Message-ID: 4830.1043975786@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

greg(at)turnstep(dot)com writes:
> If they are truly identical, then you must use the hidden 'oid' column to
> differentiate the two. No need to peek at the oid, just do this:

> DELETE FROM test WHERE oid = (SELECT oid FROM test WHERE column_id=5 LIMIT 1);

Also, if you're unfortunate enough to have this problem in a table with
no OID column, you can play the same trick with the ctid column, which
always exists (it's the physical location of the tuple). ctid is
dangerous to use for most purposes, because it's not stable over UPDATE
or VACUUM FULL, but it works perfectly well for this kind of problem.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Weaver 2003-01-31 02:19:14 FW: Converting clarion
Previous Message Vernon Wu 2003-01-31 01:15:35 How to rename and drop a column in pg7.3?