Postgres output CSV


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. \f ','
  2. \a
  3. \t
  4. \o /tmp/moocow.csv
  5. SELECT foo,bar FROM whatever;
  6. \o
  7. \q
  8.  
  9. If a field has newlines, this will break. You can do something like this instead.....
  10.  
  11. SELECT foo, bar, '"' || REPLACE(REPLACE(field_with_newilne, '\n', '\\n'), '"', '""') || '"' FROM whatever;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.