Monday, February 6, 2017

PostgreSQL: detect duplicates

Detect duplicates in at_file after a given date:
1
2
3
4
5
6
7
8
9
select * from monitor_db.at_file
 where exists (
 select 'x'
                  from monitor_db.at_file i
                 where i.file_id = at_file.file_id
                   and i.process_id = at_file.process_id
                   and i.ctid > at_file.ctid
                   and log_date > '2017-01-31'
             )