Re: [GENERAL] Delete Duplicates with Using - Mailing list pgsql-general

From Andreas Kretschmer
Subject Re: [GENERAL] Delete Duplicates with Using
Date
Msg-id 74bce063-5902-044b-7e3d-634ce17df891@a-kretschmer.de
Whole thread Raw
In response to [GENERAL] Delete Duplicates with Using  ("Igal @ Lucee.org" <igal@lucee.org>)
Responses Re: [GENERAL] Delete Duplicates with Using  ("Igal @ Lucee.org" <igal@lucee.org>)
List pgsql-general

Am 14.10.2017 um 08:20 schrieb Igal @ Lucee.org:
>
> Hello,
>
> I run the SQL query below to delete duplicates from a table. The 
> subquery is used to identify the duplicated rows (row_num is a 
> BIGSERIAL column).
>

other solution, using the CTID-column: (rows with (1,1,1) and (5,5,5) 
are identical)

test=*# select * from dubletten ; c1 | c2 | c3
----+----+----  1 |  1 |  1  1 |  1 |  1  1 |  2 |  3  2 |  3 |  4  3 |  4 |  5  4 |  5 |  5  5 |  5 |  5  5 |  5 |  5
(8 Zeilen)

test=*# with keep as (select max(ctid) as ctid from dubletten group by 
c1,c2,c3) delete from dubletten where ctid not in (select ctid from keep);;
DELETE 2
test=*# select * from dubletten ; c1 | c2 | c3
----+----+----  1 |  1 |  1  1 |  2 |  3  2 |  3 |  4  3 |  4 |  5  4 |  5 |  5  5 |  5 |  5
(6 Zeilen)

test=*#

Regards, Andreas

-- 
2ndQuadrant - The PostgreSQL Support Company.
www.2ndQuadrant.com



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: "Igal @ Lucee.org"
Date:
Subject: Re: [GENERAL] Adding identity column to a non-empty table
Next
From: Thomas Kellerer
Date:
Subject: [GENERAL] Postgres 10 manual breaks links with anchors