Monday, February 6, 2017

PostgreSQL: detect duplicates

Detect duplicates in at_file after a given date:
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'
             )