tags:

views:

1245

answers:

2

Hi

I'm trying to export a PostgreSQL table with headings to a CSV file via commandline, however I get it to export to CSV file but without headings. I need those headings as well. My code looks as follows

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

Any help would highly be appreciated

+3  A: 
COPY products_273 to '/tmp/products_199.csv' delimiters',' CSV HEADER;

as described in the manual.

Milen A. Radev
Be aware that the HEADER argument was not introduced until 8.1.
Dana the Sane
Which is, let's say, a bit rusty.
Milen A. Radev
Thx for the response running an ancient version 7 ;-(
Roland
Although 7.4 is still supported (v7.4.25 is the latest right now) I would recommend an upgrade to 8.3 ASAP. I don't want to be in your shoes if you're still using something older than 7.4.
Milen A. Radev
Unfortunately PostgreSQL 7.3.4 is the version I currently use ;-(
Roland
+1  A: 

There doesn't seem to be a flag to COPY to output the column names. Another way to do this would be to select the column information from the system catalog (pg_catalog), output that to a csv file, run your copy command and finally cat the two files together.

There are numerous export tools on the net though, so you should be able to find a one step script that does this (or write your own in bash or powershell).

Dana the Sane