Web appOpen in Telegram

PostDeleting ONLY the duplicates (leaving 1 row behind), with full control over batch sizes.

12 April 2023
P
PostgreSQL Library
Deleting ONLY the duplicates (leaving 1 row behind), with full control over batch sizes. I've seen this question come up NUMEROUS times in various forums. I've based this implementation on the work of others. (@Nikoay_S) This is a GOOD LEARNING PIECE. This seems straight forward enough. Effectively, you can limit the number of rows you have coming back. I have it set to 100 here. The trick is HAVING count(1) > 1. This means each time you run, you will get at new set to work with. Notice the way this runs, using the \WATCH command as a loop. (but it's an infinite loop. Version 16 of psql has iteration control!) [Also, this means it doesn't work in GUI tools] Each iteration is it's own transaction. When you are done, the table is bloated (it should be vacuumed). [I guess you could also use ROW_NUMBER OVER (PARTITION) rn ... WHERE rn > 1)] — SETUP drop table if exists big; create temp table big ( other_val int ); insert into big select gs % 1000 + 1 from generate_series(1, 5000000) as gs; create index on big (other_val); vacuum analyze big; DELETE from big USING (select count(1) as cnt, other_val, min(ctid) as min_ctid from big group by other_val having count(1)>1 order by other_val desc limit 100) as dupes where big.Other_val = dupes.other_val AND big.ctid > dupes.min_ctid; \watch 0.5
3 · 1.4K ·

Nearby in the feed

PPostgreSQL LibraryDo you have write queries that take forever to run? This is an approach to Batch Based processing, with independent transactions. And the ability to keep track PPostgreSQL Libraryhttps://archive.fosdem.org/2017/schedule/event/postgresql_backup/
this message
PPostgreSQL LibraryTRAINING... EnterpriseDB Offers Free Training here: https://www.enterprisedb.com/trainingPPostgreSQL LibraryThings to consider when Converting from Oracle to Postgresql This is going to be a CHAT conversation of knowledge to help others.
PPostgreSQL LibraryPostgreSQL Library@postgresql_lib · channel
624subscribers32posts in the index
Venue feed Open in Telegram

An open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog · Search · How we count