0

Below import command works fine if the nrgcore.bookmarks table is empty, please let me know how to include 'truncate table ngrcore.bookmarks' in the below command so that it first truncate the table and then import the data successfully.

psql -U nrgadmin -d enwdb -c "COPY nrgcore.bookmarks(login, application, description, centerx, centery, scale, bookmarkid, path) FROM 'D:\Bookmarks_Table\Bookmarks.csv' DELIMITER ',' CSV HEADER"

Any help/suggestion would be much appreciated.

1
  • Add the TRUNCATE statement before COPY in the -c option, separated by a semicolon. Commented Sep 3, 2018 at 13:32

1 Answer 1

2

Instead of passing inline query, You can create one sql file that contains below :

TRUNCATE TABLE nrgcore.bookmarks;

COPY nrgcore.bookmarks(login, application, description, centerx, centery, scale, bookmarkid, path) FROM 'D:\Bookmarks_Table\Bookmarks.csv' DELIMITER ',' CSV HEADER;

And pass it in your command line argument:

psql -U nrgadmin -d enwdb -f import.sql
Sign up to request clarification or add additional context in comments.

2 Comments

Glad i could help. But be careful with truncate.
Yup no problem. I'm aware of it. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.