---
title: Importing Data into PostgreSQL from a CSV File
description: 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
date: 2020-03-18
tags: Postgres, Data, CSV
source: https://brianchildress.co/blog/import-csv-into-postgres
---

# Importing Data into PostgreSQL from a CSV File

If you're using [Postgres](https://www.postgresql.org/) 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`](https://www.postgresql.org/docs/9.3/app-psql.html) 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_
```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:

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

Result:
| user_id | location | is_active | created_at |
| :------ | :------- | :-------- | :--------- |
| 10      | USA      | true      | 2020-03-08 |
| 11      | UK       | true      | 2020-03-09 |
