What is the easiest way to save PL/pgSQL output from a PostgreSQL database to a CSV file?
I'm using PostgreSQL 8.4 with pgAdmin III and PSQL plugin where I run queries from.
What is the easiest way to save PL/pgSQL output from a PostgreSQL database to a CSV file?
I'm using PostgreSQL 8.4 with pgAdmin III and PSQL plugin where I run queries from.
I had to use the \COPY because I received the error message:
So I used:
and it is functioning
psql
can do this for you:See
man psql
for help on the options used here.If you have longer query and you like to use psql then put your query to a file and use the following command:
To Download CSV file with column names as HEADER use this command:
If you're interested in all the columns of a particular table along with headers, you can use
This is a tiny bit simpler than
which, to the best of my knowledge, are equivalent.
JackDB, a database client in your web browser, makes this really easy. Especially if you're on Heroku.
It lets you connect to remote databases and run SQL queries on them.
Source jackdb-heroku http://static.jackdb.com/assets/img/blog/jackdb-heroku-oauth-connect.gif
Once your DB is connected, you can run a query and export to CSV or TXT (see bottom right).
Note: I'm in no way affiliated with JackDB. I currently use their free services and think it's a great product.