0

I tried to export PGAdmin table (Students) to csv using the following query:

Copy (Select * From public."Students") To '/Users/dar/Desktop/postgs2sqlserver.csv' With CSV;

and I got the following error:

ERROR: could not open file "/Users/dar/Desktop/postgs2sqlserver.csv" for writing: Permission denied SQL state: 42501

1 Answer 1

1

When you do a "copy", the file is created with the perms of the user running the PostgreSQL process, postgres.

You can change that file's perms to allow the user to write to it, or choose a directory that the server user already has rights to.

You may try like this in Linux to change the file owner:-

chown user file
chown user directory
chown -R user directory 

to give write permisions:-

chmod a+w file
chmod -R a+w directory
Sign up to request clarification or add additional context in comments.

3 Comments

1.How can I change the file's permissions to allow user to write? 2. How do I choose a directory that the server has rights to?
I also tried a different table "weather" with a different command and it still failed: \copy (SELECT * from weather) To '/Users/dar/Desktop/postgs2sqlserv.csv' With CSV;
the error I get with \copy is the following: Permission denied

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.