How to export table from heroku production database locally to excel from console using Ruby?

tomekfranek picture tomekfranek · Mar 22, 2013 · Viewed 7k times · Source

I know how to export table in Rails to formated Excel file: http://railscasts.com/episodes/362-exporting-csv-and-excel

But how to do that from console.

Answer

algometrix picture algometrix · Jul 11, 2014

Connect to your Heroku database by using

heroku pg:psql

Then run the sql command to get the csv file e.g.

\copy (SELECT * FROM users) TO dump.csv CSV DELIMITER ','

Use \q to exit.

After executing the commands dump.csv would have been created in your local environment