Postgres dump to CSV

Here is a simple command to dump your Postgres DB to a CSV file.

echo "SELECT * FROM MyTable;" | psql --tuples-only --field-separator ',' --no-align --host 192.168.1.5 database username

Note: this will break if your data has commas in it.

Leave A Reply
All content licensed under the Creative Commons License