Om Kumar
Om Kumar

Reputation: 41

SQL DATABASE(postgresql)

ERROR:  could not open file "C:\Users\lenovo\Downloads\Owners.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

I am trying to import a csv file into postgresql. But this error pops up. I search everywhere. But i Couldn't get the answer of it PLEASE HELP ME.

THANKS IN ADVANCE!!

Upvotes: 1

Views: 570

Answers (1)

wildplasser
wildplasser

Reputation: 44240

COPY mytable FROM /path/thefile.csv WITH CSV,HEADER; is executed by the DBMS server, the .csv-file is read by the server. The server (typically) runs as user postgres, which cannot access arbitrary users's files. (Also: the client and server don't have to be running on the same machine) There are two possible solutions to this:

  • copy the csv-file to a place where the server can access it, in /tmp/, or somewhere under its home-directory.
  • use psql's \copy mytable(col1,col2,...) FROM '/path/file.csv'... (slightly different syntax)

Upvotes: 2

Related Questions