Import CSV File Into PostgreSQL

 Create a Table in Postgres 

CREATE TABLE persons (

id SERIAL,

first_name VARCHAR(50),

last_name VARCHAR(50),

dob DATE,

email VARCHAR(255),

PRIMARY KEY (id) );

Create or Import csv file

I am creating here…

vi emp.csv

First Name,Last Name, DOB,Email

Abhishek, Yadav,18-Dec-1982,[email protected]

Deepak, Varma,20-Jan-1982,[email protected]

Connect PostgreSQL and execute below command to import the csv file into persons table

COPY persons(first_name, last_name, dob, email) from ‘/var/lib/pgsql/emp.csv’ DELIMITER ‘,’ CSV HEADER;


Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *