Return to Snippet

Revision: 6355
at May 19, 2008 06:20 by benpjohnson


Initial Code
\f ','
\a
\t
\o /tmp/moocow.csv
SELECT foo,bar FROM whatever;
\o
\q

If a field has newlines, this will break. You can do something like this instead.....

 SELECT foo, bar, '"' || REPLACE(REPLACE(field_with_newilne, '\n', '\\n'), '"', '""') || '"' FROM whatever;

Initial URL
http://pookey.co.uk/blog/archives/49-Outputting-from-Postgres-to-CSV.html

Initial Description

                                

Initial Title
Postgres output CSV

Initial Tags
sql, query, csv

Initial Language
Other