Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import a .csv file into my Hasura PostgreSQL database?

I have data in a .csv file that I want to import into my Hasura cluster's PostgreSQL database instance. What's the best way to do this?

like image 625
Kartikey Avatar asked Nov 19 '17 18:11

Kartikey


People also ask

How do I import a CSV file into PostgreSQL using Python?

First, we import the psycopg2 package and establish a connection to a PostgreSQL database using the pyscopg2. connect() method. before importing a CSV file we need to create a table. In the example below, we created a table by executing the “create table” SQL command using the cursor.


1 Answers

Create table_name with the appropriate schema to absorb your CSV data; use psql to stream data on to postgres. Execute this command:

$ psql <postgres-url> -d <database-name> -U <user-name> -c \
  "copy table_name from STDIN with delimiter as ',';" \
  < /path/to/file.csv

You will have the data from CSV file inside table table_name

like image 50
Shahidh Avatar answered Sep 29 '22 07:09

Shahidh