- Copy the query into a .sql file locally.
- Remove all newlines, because psql’s
\copy
command does not accept multiline arguments.
- Surround the query with parens and the
\copy
command, like so: \copy (select ...) TO dump.csv CSV DELIMITER ',' HEADERS
- Make sure to use
as
aliases for any column names that are the same across tables, because this method will not be as smart as Dataclips about distinguishing the column headers for those.
- pipe it to psql:
cat jeans.sql | heroku pg:psql dbcolor -a yourapp