I'm using PostgreSQL database, after I've created my table I have to populate them with a CSV file. However the CSV file is corrupted and it violates the primary key rule and so the database is throwing an error and I'm unable to populate the table. Any ideas how to tell the database to ignore the duplicates when importing from CSV? Writing a script to remove them from the CSV file is no acceptable. Any workarounds are welcome too. Thank you! : )
Asked
Active
Viewed 5,006 times
4
-
Can you use a distinct in source select? – Rod Lima Jun 18 '15 at 18:11
1 Answers
3
On postgreSQL, duplicate rows are not permitted if they violate a unique constraint. I think that your best option, is to import your CSV file on to temp table that has no constraint, delete from it duplicate values, and finally import from this temp table to your final table.

Houari
- 5,326
- 3
- 31
- 54
-
-
4@AntonBelev To learn more, search for "postgresql bulk upsert". See http://stackoverflow.com/questions/17267417/how-do-i-do-an-upsert-merge-insert-on-duplicate-update-in-postgresql, http://stackoverflow.com/questions/7019831/bulk-batch-update-upsert-in-postgresql – Craig Ringer Feb 01 '14 at 04:27