How to export table as CSV with headings on Postgresql?
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',';
Solution 1:
COPY products_273 TO '/tmp/products_199.csv' WITH (FORMAT CSV, HEADER);
as described in the manual.
Solution 2:
From psql command line:
\COPY my_table TO 'filename' CSV HEADER
no semi-colon at the end.