Re: How to delete duplicate record - Mailing list pgsql-sql

From greg@turnstep.com
Subject Re: How to delete duplicate record
Date
Msg-id b1761f04edab6a7b6d95e10f1b696b49@biglumber.com
Whole thread Raw
In response to Re: How to delete duplicate record  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List 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@turnstep.com
PGP Key: 0x14964AC8 200302100934

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

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




pgsql-sql by date:

Previous
From: "Alexander Stanier"
Date:
Subject: Referential Integrity
Next
From: Tom Lane
Date:
Subject: Re: Referential Integrity