Reputation: 1316
I have tried multiple ways to import a .csv file into Cloud SQL (PostgreSQL), with no luck.
psql -f import.sql does not work. It says that I must be a superuser to import, but that \copy works.
So I tried \copy , and that fails. I get:
postgres=> \copy ppw_raw FROM 'H:\data\data.csv' WITH (FORMAT csv);
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
So finally I try from https://console.cloud.google.com/path-to-sql-instance
I upload the .csv to a storage bucket, then click all the buttons to import the .csv (in storage bucket), to the DB/Table I want, and the user I want to import as (the user that created the table, that owns the database I am selecting),
and I get a popup message:
Import failed: Import CSV error: ERROR: relation "<my-table-name>"
does not exist.
but indeed the table exists. The create table command was successful, and when I describe the table, it exists.
I have tried three different ways now to import a .csv, I am behind on a very demanding deadline for a report.
Has anyone anywhere been able to successfully import a .csv file into Google Cloud SQL / PostgreSQL by any means?
Upvotes: 2
Views: 3744
Reputation: 503
Run the commands :
Here is the picture which I have done for first two commands in mysql:
Upvotes: 0
Reputation: 503
Run the commands :
Here is the picture which I have done for first two commands in mysql:
Upvotes: 0
Reputation: 2805
I tried different methods to import a custom CSV
file into the CloudSQL (PostgreSQL) database instance. It looks like you are trying to import data to a table that doesn't exists in your database. I had the same error, when I was trying to import to table that didn't exist.
To import CSV file, make sure that:
SQL query
add the following command SELECT * FROM products LIMIT 5;
. It will only export the first 5 records from the database, therefore it won't take much time.To import the file in the CloudSQL (PostgreSQL) database:
First make sure that the table exists in the database. Connect to your CloudSQl (PostgreSQL) instance. Run the command SELECT * FROM pg_catalog.pg_tables;
to list all the tables. If you have found your table in the list, use the exact same name for Table
when importing the data to the database.
Upload the CSV file in a bucket folder
Find the CloudSQL (PostgreSQL) instance in SQL page and click on the instance's name.
In the Instance details
page click on Import
.
In Cloud Storage file
select the CSV file from bucket.
In Format of import
, select CSV
In table
write the name of the table you want to import the data in.
Click on Import
and the data will be imported.
I have tried the methods above myself and I uploaded successfully a custom CSV file to CloudSQL (PostgreSQL).
Upvotes: 2