3

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?

2
  • 3
    Is your file on the same machine as your PostgreSQL instance? Commented Aug 11, 2016 at 18:42
  • On an unrelated matter is the delimiter a semicolon or is it a CSV file? The answer/comment @Nicarus gave is the most likely issue. Commented Aug 12, 2016 at 2:56

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good answer. I've posted a patch to the PostgreSQL mailing list to help users out with this, since this is far from the first time I've seen it. Hopefully it'll get into PostgreSQL 10.0; it's too late for 9.6 now. Link: postgresql.org/message-id/…

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.