Like here, I have a large table which stores all events in our systems, for one event type I have duplicate rows (mistakenly exported from another system several times). I need to delete them to clear out stats. The solution proposed above was to
- insert the records -- without duplicates -- into a temporary table,
- truncate the original table and insert them back in.
But in my situation I need to delete only one class of events, not all rows, which is impossible with truncate
. I'm wondering whether or not I can benefit from postgres USING syntax like in this SO answer , which offers the following solution -
DELETE FROM user_accounts
USING user_accounts ua2
WHERE user_accounts.email = ua2.email AND user_account.id < ua2.id;
The problem is that I don't have id field in this large table. So what will be the fastest decision in this situation? DELETE + INSERT from temporary table is the only option?