Re: Delete Duplicates with Using

From: "Igal (at) Lucee(dot)org" <igal(at)lucee(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Delete Duplicates with Using
Date: 2017-10-16 15:58:50
Message-ID: 1dbb5ca0-9b33-9165-cb0a-333195619ceb@lucee.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 <http://lucee.org/>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Seamus Abshere 2017-10-16 17:08:35 Re: Non-overlapping updates blocking each other
Previous Message Alex Magnum 2017-10-16 15:39:38 ORDER with CASE and Random for each case