Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql cannot find file name specified in copy command

I try this:

COPY gemeenten 
  FROM 'D:\CBS_woningcijfers_2014.csv'
  DELIMITER ';' CSV

and get this:

ERROR:  could not open file "D:\CBS_woningcijfers_2014.csv" for reading: No such file or directory

I doubled the backslashes, tried an E string, replaced \ by /, used " instead of ' but now I've run out of options. I am sure the file exists. Anybody any idea?

like image 437
Arnold Avatar asked Dec 05 '25 08:12

Arnold


1 Answers

If the file and the PostgreSQL database are on the same machine, then the path and/or name of the file are not correct.

If the file is on your local machine and the database is on another, you cannot use the COPY command in SQL. You have two main choices to make this work:

1) Use psql \copy from your local machine. The syntax is similar, but it will transfer from your local to the remote. The docs are pretty helpful: https://www.postgresql.org/docs/9.5/static/app-psql.html#APP-PSQL-META-COMMANDS-COPY

2) Upload the file to the remote machine and then execute your command. Just make sure you are referencing the correct path and filename.

like image 98
Nick Avatar answered Dec 07 '25 20:12

Nick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!