Copy table in postgres if it already exists

0

I have managed to get the table I need thanks to the question: postgres copy tables

sudo pg_dump -i -h server-address -p 5432 -U postgres -t product_attribute_line -F p -b -v -f "product_attribute_line.sql" database-name

My problem comes when I do

psql -d database -U postgres -f product_attribute_line.sql

, and the error is that it is already created:

psql:product_attribute_line.sql:1486: ERROR:  constraint "product_attribute_line_write_uid_fkey" for relation "product_attribute_line" already exists

It would be easier if you could delete it to create it again, but the problem is that if I delete it the database will no longer work.

I tried to do insert into but I can not get it to work, it does not work when doing an import / export with pg_admin. Any ideas?

Thank you.

    
asked by Joshua 04.05.2018 в 13:21
source

1 answer

0

What it tells you is that there is already a constrain with that name you must remove it before doing the psql or remove it from the script that you are going to upload.

To eliminate a constraint you just have to click on the table, on the plus sign that appears on one side, then where it says constraints and right click -delete on the one that generates conflict.

This assuming you use pgadmin III

    
answered by 04.05.2018 в 15:19