Har du prøvet dette? Jeg har ikke psql lige nu til at teste det.
echo “COPY (SELECT * from schema.products) TO STDOUT with CSV HEADER” | psql -o '/home/localfolder/products.csv'
Detaljer:
-o filename Put all output into file filename. The path must be writable by the client.
echo builtin + piping (|) pass command to psql