Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andreyshuster/27ccc3a2d8537c817df3a6d60af23109 to your computer and use it in GitHub Desktop.
Save andreyshuster/27ccc3a2d8537c817df3a6d60af23109 to your computer and use it in GitHub Desktop.
How to output result of psql query to a file

From PSQL console

$ psql <postgres connection string>
=> \o result-filename.txt
=> SELECT * from the table

Another variant (CSV export)

COPY (SELECT foo, bar FROM baz) TO '/tmp/query.csv' (format csv, delimiter ';')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment