Permission denied when trying to import a CSV file from PGAdmin
The user Postgres
must have read access on the file from which you are about to copy.
Look at this article to see how to modify files' security access on Windows.
The permissions article mentioned in the answer by Houari and Flimzy is a good reference material, but a direct answer (the quick fix I used) is:
- Right click the folder containing the data file(s) that permission was denied to and then click Properties.
- In the Folder's Properties window, select the Security tab.
- Click the Edit button.
- In the "Permissions for the folder" window that opened, click the Add... button.
- Type
Everyone
into the "Enter the object names to select" text area box. - Click OK and the window will close.
- Verify that the default Read & Execute permissions were set to Allow via the check checkbox in the previous window.
- Click OK and the window will close.
- Click the Apply button in the Folder Properties window.
Now you can run the SQL COPY statement that needs to access those files.
- Once done, return to the Folder's Properties window.
- Click the Edit button.
- Select the
Everyone
entry in the "Group or user names:" field. - Click the Remove button.
- Click OK on the remaining open windows.
The permissions have now been returned to what they were.
Ok, this is how got COPY command working,to export a table to CSV, step by step. Pls note that I am using pgAdmin 111.
- Create the target folder you want to export a table to. E.g C:\myExports
- Set a read/write permission on this folder following the steps below :
Right click the folder containing the data file(s) that permission was denied >to and then click Properties.
In the Folder's Properties window, select the Security tab. Click the Edit button.
In the "Permissions for the folder" window that opened, click the Add... button. Type Everyone into the "Enter the object names to select" text area box.
Click OK and the window will close. Verify that the default Read & Execute permissions were set to Allow via the >check checkbox in the previous window. Click OK and the window will close.
Click the Apply button in the Folder Properties window.
This is the tricky part, inside myExports folder create a blank CSV file with your desired name.E.g employee.csv
Then run the Copy command like this :
copy employee to 'C:\myExports\employee.csv' delimiter ',' csv;
employee is the table name in this example..
Hope this helps.