Re: [GENERAL] Delete Duplicates with Using
От | Igal @ Lucee.org |
---|---|
Тема | Re: [GENERAL] Delete Duplicates with Using |
Дата | |
Msg-id | 1dbb5ca0-9b33-9165-cb0a-333195619ceb@lucee.org обсуждение исходный текст |
Ответ на | Re: [GENERAL] Delete Duplicates with Using (Andreas Kretschmer <andreas@a-kretschmer.de>) |
Ответы |
Re: [GENERAL] Delete Duplicates with Using
|
Список | pgsql-general |
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.
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 по дате отправления: