0

I am using

\COPY ( SELECT * FROM person LEFT JOIN car ON car.id=person.car_id ) TO 'c:/Users/nick-/Downloads/results.csv' DELIMITER ',' CSV HEADER; 

and am getting the error

ERROR: syntax error at or near "TO" LINE 6: TO 'c:/Users/nick-/Downloads/results.csv' 

I've also tried COPY rather than \COPY but I get this error

ERROR: could not open file "c:/Users/nick-/Downloads/results.csv" for writing: Permission denied HINT: COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy. 

I have tried using all of the below

c:/Users/nick-/Downloads/results.csv c://Users//nick-//Downloads//results.csv 'c:\Users\nick-\Downloads\results.csv' 'c:\\Users\\nick-\\Downloads\\results.csv' 

and none have worked.

6
  • It looks like your Postgres server is running under a different user account which does not have permission to write to your personal home directory (C:\users\nick). Either change your Downloads directory permissions to allow Postgres access - or have Postgres write to a folder that it does have permission to write to (such as a folder within C:\Program Files\Postgres\... or C:\Users\Public\Documents) Commented Sep 4, 2020 at 0:42
  • @Dai I just did this, in the C:\Users\Public\Documents using both that syntax and 'C:/Users/Public/Documents' and got ERROR: syntax error at or near "TO" LINE 6: TO 'C:/Users/Public/Documents' again. So I have gotten passed the access, but now am having the same problem as listed above. Commented Sep 4, 2020 at 0:53
  • What version of Postgres are you using? Commented Sep 4, 2020 at 0:53
  • @Dai I'm using windows verson 13 Commented Sep 4, 2020 at 0:58
  • 1
    Meta-commands (like \COPY) in psql must fit in a single line. See also Use psql's \copy for a multi-line query Commented Sep 4, 2020 at 1:06

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.