Search code examples
postgresqlpgadmin-4

how to import csv dataset into postgres. I tried solution on other pages but they are not working


My query:

copy public.bank from "C:\Users\JAY SARDAR\Desktop\bankdetails.csv" DELIMITER ',' , csv HEADER;

Error

ERROR: syntax error at or near ""C:\Users\JAY SARDAR\Desktop\bankdetails.csv""
LINE 1: copy public.bank from "C:\Users\JAY SARDAR\Desktop\bankdetai...

enter image description here


Solution

  • for me following command helped in psql shell. The error i was getting was because sql file had ANSI characters which are invisible in UTF8. you can remove such character in notepad++ then run command

    psql -h localhost -d databasename -U username-f "c://path_to_file.sql"