Próbowałeś tego? Nie mam teraz psql, aby go przetestować.
echo “COPY (SELECT * from schema.products) TO STDOUT with CSV HEADER” | psql -o '/home/localfolder/products.csv'
Szczegóły:
-o filename Put all output into file filename. The path must be writable by the client.
echo builtin + piping (|) pass command to psql