Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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','; 
like image 308
Elitmiar Avatar asked Jul 13 '09 15:07

Elitmiar


People also ask

How do I export a table from PostgreSQL to CSV?

The easiest but the most efficient way to export data from a Postgres table to a CSV file is by using the COPY command. COPY command generates a CSV file on the Database Server. You can export the entire table or the results of a query to a CSV file with the COPY TO command.

How do I export data from pgAdmin to CSV?

From the query editor, once you have executed your query, you just have to click on the "Download as CSV (F8)" button or use F8 key.


1 Answers

COPY products_273 TO '/tmp/products_199.csv' WITH (FORMAT CSV, HEADER); 

as described in the manual.

like image 110
Milen A. Radev Avatar answered Sep 20 '22 11:09

Milen A. Radev