The other day I tried to import a CSV record of data via PGAdmin4. The total number of records is ~300,000.
Setup
- Django Project
- Postgres
- PGAdmin4
Goal
- Import CSV data via PGAdmin4 and populate database schema
What I did
- Run PGAdmin4 as administrator
- Create a DB table
- Use COPY FROM $schema ‘path to CSV file’ delimiter ‘;’ header;
- Execute the query
Issue
- Permission Denied
Solution
- Go to your CSV file right click and add “everyone”
- Grant all permission to the user by clicking on all Checkboxes
- Done
DROP TABLE voters;
CREATE TABLE voters(voter_id INT NOT NULL,
first_name VARCHAR(100),
last_name VARCHAR(100),
registration_number VARCHAR(255),
polling_station VARCHAR(100),
date_of_birth DATE,
gender VARCHAR(100),
ward VARCHAR(100),
area VARCHAR(100),
constituency VARCHAR(100),
province VARCHAR(100),
PRIMARY KEY (voter_id));
SELECT * FROM voters;
COPY voters(voter_id,first_name,last_name,registration_number,polling_station,date_of_birth,gender,ward,area,constituency,province)
FROM 'C:\Users\anikwai_w\Desktop\SIEC\New\voters.csv'
CSV HEADER;