At times we need to export the data from database to a comma seperated file(CSV) through psql command terminal, here is a quick and easy way to do it
open terminal
[root@vishy vishy]#su postgres
bash-3.2$psql <db_name>
prdideas=# \f ‘,’
Field separator is “,”.
prdideas=# \a
Output format is unaligned.
prdideas=# \t
Showing only tuples.
prdideas=# \o ~/results.csv
prdideas=#select <SQL STATEMENT>
prdideas=#\o
prdideas=#\q
Filed under: OpenSource
Trackback Uri


[...] PostgreSQL data to csv file using psql [...]… [full post] Vishwajeet Singh Learning is an Art opensourcehowtopostgresqlpsql 0 0 [...]