Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
753 views
in Technique[技术] by (71.8m points)

sql - I am trying to copy a file, but getting error message

I am new to postgres, probably missing something silly like (the correct name of my directory). Can someone guide me?

I am following book instructions, Practical SQL by Anthony DeBarros

Code:

copy us_counties_2010 from 'C:UsersobellaOneDriveDesktopus_counties_2010.csv' with (FORMAT CSV, HEADER);

Error:

ERROR: could not open file "C:UsersobellaOneDriveDesktopus_counties_2010.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

copy us_counties_2010 from 'C:UsersobellaOneDriveDesktopus_counties_2010.csv' with (FORMAT CSV, HEADER);

Expected:

Query returned successfully: 3143 rows affected

Actual:

ERROR: could not open file "C:UsersobellaOneDriveDesktopus_counties_2010.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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As the message tells you, Postres is not allowed to read the file.

If you want to fix that open the Task Manager, and click on "Show processes from all users". Look for the rows with the image name postgres.exe (likely more than one). Remember the value in the column "User Name" (it's probably NETWORK SERVICE). Open the properties of your file, add that user in the "Security" tab and grant read access to them.

Or use psql's copy as the message suggests.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...