Importing Data into PostgreSQL from a CSV File

Here are the simple steps you need to import data into your Postgres Database from a .csv file. access the Docker Engine's API from inside a container, Docker makes it really easy to do

If you’re using Postgres as a database and need to import data from a .csv file, it’s really easy to do using psql.

Before you start, you’l need:

  1. psql running in an interactive terminal
  2. A Postgres database with a table you want to import data, we’ll call it user_data
  3. Data in a .csv file

Your .csv file should have matching headers to the column names in your Postgres table

Example file: users.csv

user_id,location,is_active,created_at
10,USA,true,2020-03-08
11,UK,true,5678,2020-03-09
...

To import use the COPY command:

COPY user_data from 'users.csv' WITH DELIMITER ',' CSV HEADER;

Result:

user_idlocationis_activecreated_at
10USAtrue2020-03-08
11UKtrue2020-03-09