Alexa
Alexa

Reputation: 41

Why doesn't Copy or \copy work for me in Pgsql?

I am trying to import data from a CSV into Postgres. I have tried the following and got the following errors:

COPY TA_Files 
FROM 'C:\Users\ABla47\Documents\TA 11.19.21.csv'
DELIMITER ','
CSV HEADER;
ERROR:  could not open file "C:\Users\ABla47\Documents\TA
11.19.21.csv" for reading: Permission denied

HINT:  COPY FROM instructs the PostgreSQL server process to read a
file. You may want a client-side facility such as psql's \copy.

SQL state: 42501

Then I tried:

\COPY TA_Files 
FROM '\Documents\TA 11.19.21.csv'
DELIMITER ','
CSV HEADER;
ERROR:  syntax error at or near "\"
LINE 1: \Copy TA_Files

What format do I need to use to get the data from the CSV into the table?

Upvotes: 4

Views: 8205

Answers (2)

John Griffin
John Griffin

Reputation: 1

Late but just had this problem and hadn't seen this solution on stackoverflow yet. This was the simplest solution for me.

https://www.commandprompt.com/education/how-to-fix-permission-denied-error-while-importing-a-csv-file-in-postgresql/

just go to file properties -> security -> edit -> then in 'object names' type 'Everyone'. ->apply changes

Upvotes: 0

luismcp
luismcp

Reputation: 41

this worked for me:
I placed the files in C:\Program Files\PostgreSQL\14\pgAdmin 4 directory and copied it from there.

COPY superstore_people(person, region)
FROM 'C:\Program Files\PostgreSQL\14\pgAdmin 4\superstore_people.csv'
DELIMITER ','
CSV HEADER;

Upvotes: 3

Related Questions