Re: FAQ addition: deleteing all but one unique row - Mailing list pgsql-patches

From Tom Lane
Subject Re: FAQ addition: deleteing all but one unique row
Date
Msg-id 5496.1044890736@sss.pgh.pa.us
Whole thread Raw
In response to FAQ addition: deleteing all but one unique row  (greg@turnstep.com)
Responses Re: FAQ addition: deleteing all but one unique row  (greg@turnstep.com)
List pgsql-patches
greg@turnstep.com writes:
> + <PRE>
> +        DELETE FROM mytable WHERE ctid !=
> +          (SELECT ctid FROM mytable WHERE id=12 LIMIT 1);
> + </PRE>
> +
> +     <P>In the above example, all rows in the table named 'mytable' having a value
> +        of 12 in the 'id' column will be deleted except for one.

You haven't actually tested this advice, have you?

The delete as given will delete all but one row, full stop.

Or at least it would if it worked at all.  There's no != operator
defined for CTID.  (You could get around that with "NOT ctid =".)

            regards, tom lane

pgsql-patches by date:

Previous
From: greg@turnstep.com
Date:
Subject: FAQ addition: deleteing all but one unique row
Next
From: greg@turnstep.com
Date:
Subject: Re: FAQ addition: deleteing all but one unique row