How to Import CSV File Data Into a PostgreSQL Table

We have different data sources for databases, especially during test case design, CSV files adds more compatibility and flexibility.

TL;DR: COPY tablename FROM ‘/path/to/file.csv’ WITH (FORMAT csv);

CSV Format

CSV stands for comma separated value. It’s a portable data format, stores data in a text format separated with commas.

Impoting CSV Into a PostgreSQL Table

PostgreSQL offers COPY … FROM syntax to import CSV into a PostgreSQL table. You can read more about COPY statement from this link.

Copy statement also has parameters for HEADERS, different delimiters.

You can import CSV Into a PostgreSQL Table like:

COPY tablename FROM '/path/to/file.csv' WITH (FORMAT csv);

PostgreSQL offers very simplified usage.

Today we covered importing a csv topic, please leave a comment below if you have question or something to add.

A new post everyday, subscribe now and don’t miss it!

Subscribe to our newsletter for cool news

Hi! I’m an IT Specialist

I want to hear from you! I am Working with enterprises for 10+ years to improve their infrastructure and efficiency.

Get in touch with me.

Leave a Reply