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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With