I just started trying to learn sql. I am a complete noob in programming (just so you know).
So my problem is that I am trying to copy an existing csv file in a sql table in pgAdmin4 1.5.
So I am running this query to copy the data from the csv:
COPY console_games FROM '/users/user1/Desktop/ConsoleGames.csv' DELIMITER ',' CSV HEADER;
And I get this result:
********** Error **********
ERROR: could not open file "/Users/user1/Desktop/ConsoleGames.csv" for reading: Permission denied
SQL state: 42501
I have changed the permissions of this file for all users to be read and write, but I still get the error.
Please help! (considering that I am an absolute newbie)
If you need more info to solve the problem I will try my best to find it!
Use PgAdmin4's bulk-load features to import the CSV. This will do a COPY ... FROM STDIN
behind the scenes. PgAdmin4 will access the file with your user's permissions, not those of the postgres server like a direct COPY
from file will.
I solved this problem by creating a folder named Database in the PostgreSQL bin where I save all the data files that I want to work on. I use pgAdmin4 on both Mac and Windows. Whereas it is rather straightforward to find the bin on Windows, it is a bit tricky to find it on Mac because the Library where the bin is kept is hidden. Try to save your files on C:\ProgramFiles\PostgreSQL\10\bin\Database
if you are using Windows and /Library/PostgreSQL/10/bin/Database/
if you are using Mac. The Library can be found by pressing command+shift+g
and type ~/Library
on the go to folder. Your Mac will require your password to make changes in the Library. After saving your data files here, your code on pgAdmin4 should be like this:
COPY console_games FROM 'C:\ProgramFiles\PostgreSQL\10\bin\Database\ConsoleGames.csv' DELIMITER ',' CSV HEADER;
or
COPY console_games FROM '/Library/PostgreSQL/10/bin/Database/ConsoleGames.csv' DELIMITER ',' CSV HEADER;