Re: How to delete duplicate record

From: greg(at)turnstep(dot)com
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to delete duplicate record
Date: 2003-02-10 14:44:10
Message-ID: b1761f04edab6a7b6d95e10f1b696b49@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Abdul Wahab Dahalan:
>> Here I've 7 duplicated records and tried to delete 6 from them.

Stephan Szabo:
> delete from biztypes where ctid in (select ctid from biztypes where
> bizid='B116' limit 6);

A more general form of the "delete all but one" is:

DELETE FROM biztypes WHERE ctid !=
(SELECT ctid FROM biztypes WHERE bizid='B116' LIMIT 1);

You can also usually use the oid column instead of the ctid column.

System columns explained:
http://www.gtsm.com/cgi/psearch?page=ddl-system-columns.html;q=ctid;c=0

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200302100934

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iD8DBQE+R7oUvJuQZxSWSsgRAloaAJ9AkNjjYvCuOB8wanR8RoouEmU6eACg5YVX
3R+q3GDK5Pblu7L7z3TIEnE=
=qM8Y
-----END PGP SIGNATURE-----

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-02-10 15:09:52 Re: Referential Integrity
Previous Message val 2003-02-10 10:25:00 index strategies