Question posted 2013 · +6 upvotes
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.
Accepted answer +18 upvotes
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
2 code variants in this answer
- Variant 1 — 1 lines, starts with
heroku pg:psql - Variant 2 — 1 lines, starts with
copy (SELECT * FROM users) TO dump.csv CSV DELIMITER ','
Top excel Q&A (6)
- Shortcut to Apply a Formula to an Entire Column in Excel +335 (2011)
- How should I escape commas and speech marks in CSV files so they work in Excel? +136 (2012)
- Convert xlsx to csv in linux command line +96 (2012)
- How to create a link inside a cell using EPPlus +50 (2011)
- IF statement: how to leave cell blank if condition is false ("" does not work) +44 (2013)
- T-SQL: Export to new Excel file +44 (2012)
excel solutions on this site
— top 20%.