title: How to collect failed keys when Postgres csv copy throws foreign key constraint error
body: <p>In trying to copy a csv file with foreign key dependence, I get the the error:</p>
  
  <blockquote>
    <p>ERROR:  insert or update on table violates foreign key constraint</p>
  </blockquote>
  
  <p>The copy query is like so:</p>
  
  <pre><code>\copy table_name FROM '/location_of_csv' WITH DELIMITER ',' CSV HEADER;
  </code></pre>
  
  <p>Is there a way to collect all the failed foreign keys and print them out before postgres throws the error?</p>
  
  <p>Is there a command to ignor rows that violate the constraint?</p>