1

I am trying to import data to a postgres database in heroku. I am able to upload the correct schema to heroku by using the command:

heroku pg:psql -a [app name] < db/structure.sql

so now when I run heroku pg:psql and connect to my database I can run:

\dt

and it lists all of the tables that I want. However, only the schema is uploaded, not the actual data. I have looked over a bunch of different ways to upload databases to heroku, but have been unable to get any to work. I was wondering if there is an easy way to import local csv data to heroku. Locally, I can run:

sqlite3 development.sqlite3
.mode csv
.import [table name] [filename]

And it imports the data that I want. Is there a similar way to do this for heroku databases? I know that heroku uses postgres and not sqlite3, but since I was able to load the schema easily, I thought there might be an easy way to upload data. This is my first ruby on rails project I've ever attempted to publish, so any guidance would be appreciated! Thanks!

1 Answer 1

0

Upload your csv to heroku and run

COPY zip_codes FROM '/path/to/your_file.csv' DELIMITER ',' CSV;

in pg shell

Look https://gist.github.com/jboesch/5605747, Importing csv to heroku postgres how you can do it

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the feedback! However, when I run this code I get the error: ERROR: must be superuser to COPY to or from a file. I'm not sure why I wouldn't be a superuser since I'm just working locally from my computer. Any ideas? I've tried "alter user <username> superuser" but then it gives me an error that says "must be superuser to alter superusers"
If you can't set your user as superuser, try this gem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.