Run single Rails test« an older post
a newer one »Emacs lowercase

Postgres export to a CSV

Snippet

Easy export to a CSV file, with headers.

# sql
\COPY (SELECT * FROM report_view_table) TO 'export.csv' DELIMITER ',' CSV HEADER;
 
# bash
psql $DATABASE -c "\COPY (SELECT * FROM report_table) TO 'export.csv' DELIMITER ',' CSV HEADER;"

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.