Postgres select как csv

-- To stdout
COPY (select * from table) TO STDOUT WITH CSV HEADER;

-- To file
COPY (select * from table) TO '/table.csv' WITH CSV HEADER;
Mattiboi