How to upload or export data to/from postgresql database using csv file

--

1. Upload data to a particular table.
Assuming the csv file have a header row, run below commands

mydb=>\copy student(first_name, last_name, dob, email from 'student.csv' delimiter ',' csv header;

2. Export all data of a table to a csv file

mydb=>\copy student to 'student1.csv' delimiter ',' csv header;

3. Export selected columns of a table to a csv file

mydb=>\copy student(first_name,email) to 'student2.csv' delimiter ',' csv header;

--

--

Himanshu Pratap
Himanshu Pratap

Written by Himanshu Pratap

System Administrator and Full stack web developer.

No responses yet