Import csv file and update existing table in Postgres

3.7k Views Asked by At

I have a Postgres database on Heroku. I connect to it using pgadmin. I exported a table data to csv. Edited some of the cells and now I want to replace the same table with the corrected csv. But when I try to import the csv I get this error

Error while importing updated csv on pgadmin

I researched on this error. I understood that it tries to add more rows to existing table and the primary key clashes. But I couldn't get my solution. I want to replace the table with new updated csv.

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER
SQL>begin;
BEGIN
Time: 0.366 ms
SQL>truncate table t;
TRUNCATE TABLE
Time: 3.068 ms
SQL>select * from t;
 t
---
(0 rows)

Time: 2.844 ms
SQL>copy t from '/tmp/t';
COPY 2
Time: 1.693 ms
SQL>select * from t;
               t
-------------------------------
 2014-10-09 08:09:58.241592+00
 2015-06-17 09:18:05.731139+00
(2 rows)

Time: 1.823 ms
SQL>end;
COMMIT
Time: 78.102 ms