How to export table as CSV with headings on Postgresql?

Elitmiar picture Elitmiar · Jul 13, 2009 · Viewed 444.1k times · Source

I'm trying to export a PostgreSQL table with headings to a CSV file via command line, however I get it to export to CSV file, but without headings.

My code looks as follows:

COPY products_273 to '/tmp/products_199.csv' delimiters',';

Answer

Milen A. Radev picture Milen A. Radev · Jul 13, 2009
COPY products_273 TO '/tmp/products_199.csv' WITH (FORMAT CSV, HEADER);

as described in the manual.