Published in: Other
URL: http://pookey.co.uk/blog/archives/49-Outputting-from-Postgres-to-CSV.html
\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;
Comments
Subscribe to comments
You need to login to post a comment.

After much pain:
COPY (SELECT foo,bar FROM whatever) TO '/tmp/dump.csv' WITH CSV HEADER
is cleaner and nicer and does escaping where needed for you