1
copy (select * from TABLE_NAME) TO '/home/name/teste.csv';

This is the command line, it seems pretty simple I've read the documentation on this link (https://www.postgresql.org/docs/9.6/sql-copy.html), checked my postgresql version and when I run the code it gives me this error

ERROR:  could not open file "/home/name/teste.csv" for writing: No such file or directory

********** Error **********

ERROR: could not open file "/home/name/teste.csv" for writing: No such file or directory
SQL state: 58P01

The file is there, checked with 'pwd' the path an everything seems ok, also tried the code with "WITH CSV" in the end and nothing. Anyone seeing something I'm not?

3
  • 4
    The path needs to exist on the server and the OS user that runs the server needs to have the privileges to write there Commented Nov 19, 2019 at 18:51
  • It does, the csv files has the privileges and postgresql also (pgadmin in my case) Commented Nov 19, 2019 at 19:23
  • pgAdmin runs on the client, not on the server. So giving "pgAdmin" privileges (whatever that is supposed to mean) is not enough. Commented Nov 19, 2019 at 19:36

2 Answers 2

1

For this command to work, there needs to be /home/name on the database server, and the operating system user postgres must have write access to that directory.

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

Comments

0

The file teste.csv needs to be placed in the directory home/name/ in the database server, not in the client. The database user also needs to have the necessary permissions to access the file.

An option to do that without moving the file into the database server is to use the stdin of psql from your client console:

$ cat teste.csv | psql yourdb -c "COPY tabela_teste FROM STDIN;"

abs!

Comments

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.