Cuet Cuet
Cuet Cuet

Reputation: 33

Permission denied when trying to export CSV in Postgres

When trying to create a csv file in Postgres 11, I get the error "Permission denied" I am using windows 10

I have tried different methods found in different webs to no avail, the methods I have tried are: using the Documents folder, using the D:, C:, drive and adding permission in the security section of the folder properties. None of these solutions has worked. I have also tried adding the Postgres user in the Services (Administrative Tools) however that did not work either.

test=# \copy (SELECT * FROM person LEFT JOIN car ON car.id = person.car_id) TO 'c:/desktop' DELIMITER ',' csv HEADER;

I was expecting to get the csv file, however, I get:

c:/desktop: Permission denied

Upvotes: 1

Views: 3416

Answers (1)

user330315
user330315

Reputation:

You need to provide a file name, not a directory, e.g. TO 'c:/desktop/export.txt'.

But on Windows there is no real (physical) directory c:\Desktop, that's a "virtual" directory simulated by the Windows explorer. The actual directory is inside the current user's %USERPROFILE% directory, e.g. c:\Users\cuet\Desktop.

You need to make sure you specify a valid physical path, not a "logical" one. e.g.

TO 'c:/Users/cuet/Desktop/export.txt'

(assuming your Windows user is cuet)

To find the correct path for your desktop you can use:

echo %USERPROFILE%\Desktop

In a Windows command prompt (cmd.exe)

Upvotes: 6

Related Questions