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

From Igal @ Lucee.org
Subject Re: [GENERAL] Delete Duplicates with Using
Date
Msg-id 1dbb5ca0-9b33-9165-cb0a-333195619ceb@lucee.org
Whole thread Raw
In response to Re: [GENERAL] Delete Duplicates with Using  (Andreas Kretschmer <andreas@a-kretschmer.de>)
Responses Re: [GENERAL] Delete Duplicates with Using
List pgsql-general
Andreas,

On 10/15/2017 11:53 PM, Andreas Kretschmer wrote:
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


I like this solution, but would using a subquery be much slower than the implicit join of `using`?  My tables are not big in Postgres-standards, so it's probably not an issue, but I'm trying to learn as much as I can about Postgres now that I'm getting ready to move it to production.

Thanks,

Igal Sapir
Lucee Core Developer
Lucee.org

pgsql-general by date:

Previous
From: Alex Magnum
Date:
Subject: [GENERAL] ORDER with CASE and Random for each case
Next
From: Seamus Abshere
Date:
Subject: Re: [GENERAL] Non-overlapping updates blocking each other