title: Continuing a transaction after primary key violation error
body: <p>I am doing a bulk insert of records into a database from a log file. Occasionally (~1 row out of every thousand) one of the rows violates the primary key and causes the transaction to fail. Currently, the user has to manually go through the file that caused the failure and remove the offending row before attempting to re-import. Given that there are hundreds of these files to import it is impractical.</p>
  
  <p><strong>My question:</strong> How can I skip the insertion of records that will violate the primary key constraint, without having to do a <code>SELECT</code> statement before each row to see if it already exists?</p>
  
  <p><em>Note: I am aware of the very similar question <a href="https://stackoverflow.com/questions/1054695/continue-after-primary-key-violation-error" title="1054695">#1054695</a>, but it appears to be a SQL Server specific answer and I am using PostgreSQL (importing via Python/psycopg2).</em></p>