postgres dump query to file

\copy (select fields from table where something=otherthing) to '/tmp/test.csv' with HEADER CSV;