Your query does not work because Redshift does not resolve DELETE after the WITH clause. Only SELECT and UPDATE and some others are allowed (see WITH clause )
Solution (in my situation):
I had an id column in my events table that contained duplicate rows and uniquely identified the record. This id column matches your record_indicator .
Unfortunately, I was unable to create a temporary table because I used the following error using SELECT DISTINCT :
ERROR: Intermediate result row exceeds database block size
But it worked like a charm:
CREATE TABLE temp as ( SELECT *,ROW_NUMBER() OVER (PARTITION BY id ORDER BY id) AS rownumber FROM events );
leads to the temp table:
id | rownumber | ... ---------------- 1 | 1 | ... 1 | 2 | ... 2 | 1 | ... 2 | 2 | ...
Now duplicates can be removed by deleting rows having rownumber greater than 1:
DELETE FROM temp WHERE rownumber > 1
After that, rename the tables and made by you.
source share