Clock Blog
Exporting Postgres Tables as CSV
If you need to get a quick CVS of a large query output to a client in a CSV and are using PgAdmin3 or some other GUI tool running on your local machine you might want to considering running this command on the database server directly.
echo "COPY (SELECT * FROM \"User\") TO STDOUT CSV;" | psql -U postgres BigCompanyDatabase | gzip > Users-`date +%F-%H%M`.csv.gzThis will then email you the file. NOT TO BE USED FOR ANYTHING OVER 2MB
mutt -s 'User Export' -a Users-`date +%F-%H%M`.csv.gz -- paul.serby@clock.co.uk < /dev/null
PgAdmin3, over SSH, on a 2Mbit line, took 30 mins to pull 11,000 rows. With the command line version it was in my inbox in less than a second.
Like what you've read?