[clue-tech] postgres CSV export with headers

Jack Parker jack.parker4 at verizon.net
Wed Dec 13 13:46:48 MST 2006


Typically if the database does not handle it for me, I do something like
output first the list of columns with the same delimiter...

select 'hardcoded, text, ...' from sometable where rownum = 1 -- or the
equivalent.

Then do the real select.

With Informix, I pull the list of columns from the system catalogues.

You may have trouble with stderr type messages (n rows selected, white space
etc).  Which you would want to parse out.

Check out comp.databases.postgres - or whatever, this is something that
surely must have been done before.

j.
----- Original Message ----- 
From: "Dave Price" <kinaole at gmail.com>
To: "CLUE tech" <clue-tech at cluedenver.org>
Sent: Wednesday, December 13, 2006 3:25 PM
Subject: [clue-tech] postgres CSV export with headers


> Cluefull Ones,
>
> I have looked and looked, and cannot find an answer to a simple challenge.
>
> I want to export a CSV file from postgres, but I would like to include
> the collumn names as the top row of the file to make it easier for
> folks who ope the file in 'a spreadsheet of their choice' to
> undersatand the data.
>
> The CSV export is pretty simple, if I am willing to add the headers by
hand:
>
> psql foo -c "begin; create table blah as select * from my_summary
> order by provider, period_end; copy  blah to '/tmp/blah.csv' CSV;
> rollback "
>
>
> I cannot find a switch or other option that I can switch on to achieve
> this.  Any hints.
>
> -- 
> aloha (and thanks in advance),
> dave
> _______________________________________________
> clue-tech mailing list
> clue-tech at cluedenver.org
> http://www.cluedenver.org/mailman/listinfo/clue-tech




More information about the clue-tech mailing list