Export data from Postgres as CSV

Exporting data from Postgres as a CSV or tab delimited file can be fairly simple using the COPY command. Examples below.

Export an entire table as CSV:

Export an entire table as CSV with Header:

Export query as CSV:

Export query as data tab delimited text file:

Export data directly to file (requires superuser permissions):

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">