title: Add a unique constraint but ignore existing table data
body: <p>I wish to add a unique constraint to a table using the following query -</p>
  
  <pre><code>ALTER TABLE events ADD CONSTRAINT events_timestamp_request_session_key UNIQUE (event_timestamp, request_id, session_id);
  </code></pre>
  
  <p>The query is valid, however on one database the existing data does not meet the constraint, and so the query fails -</p>
  
  <blockquote>
    <p>ERROR:  could not create unique index "events_timestamp_request_session_key"<br>
    DETAIL:  Key (event_timestamp, request_id, session_id)=(2017-07-05 14:53:25.475246+00, a55df6-8533e322cd-aa9d57-87e2, 132443) is duplicated.</p>
  </blockquote>
  
  <p>It is expected that there would be a few duplicates, but unfortunately I cannot simply delete or alter them.</p>
  
  <p>Is there any way to add the constraint as required, while ignoring the existing data in the table?</p>