How to import data from .CSV in PostGres table in a simple way?

random

How to import data from .CSV in PostGres table in a simple way?

Importing data from a CSV file into a Postgres table


In this post I will explain how to import .CSV file bulk data into Postgres table. Here we use COPY command to copy data between a file and a table in PostgreSQL.

In a Query: I create a table named Sample_Test using below Query

create table,how to create table in PostgreSQL

And I have a .CSV data file with all column names available in our table.

Copy data from .CSV to postgres table

Now execute the below query to copy data from .CSV file to the table Sample_Test.


To verify execute the select query.

Select * from Sample_Test

Output:

 
Note:
  • All the columns should be in sequence
How to import data from .CSV in PostGres table in a simple way? Reviewed by Ravi Kumar on 2:23 PM Rating: 5

2 comments:

  1. what do you do if the csv file doesn't live on the db server?

    ReplyDelete
  2. Thank you so much for this article. I've been googling for the past hour for a straight forward answer and came accross this, and it works perfectly

    ReplyDelete

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form

Name

Email *

Message *

Powered by Blogger.