Save PSQL query output to CSV file in Greenplum

Post date: Jun 05, 2013 8:32:55 AM

1. Copy (Select * From test) To '/tmp/test.csv' With CSV;

\copy (Select * From test) To '/tmp/test.csv' With CSV

2. psql -d sachi -t -A -F"," -c "select * from employees" > employees.csv

3. 

$psql sachi 

psql>\o '/tmp/output.csv' 

psql>SELECT * from employees; 

psql>\q

In terminal (while connected to the database) set output to the cvs file

1) set field seperator to ',' by:

\f ','

2) set output format unaligned:

\a

3) show only tuples

\t

4) set output

\o '/tmp/yourOutputFile.csv'

5) execute your queryselect * from YOUR_TABLE

6) output

\o