Save PSQL query output to CSV file in Greenplum

posted Apr 28, 2017, 4:12 PM by Sachchida Ojha
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
Comments