I need to export a big table to csv file and compress it.
I can export it using COPY command from postgres like -
COPY foo_table to \'/tmp/foo_table.csv
You can use directly, as per docs, https://www.postgresql.org/docs/9.4/sql-copy.html
COPY foo_table to PROGRAM 'gzip > /tmp/foo_table.csv' delimiters',' CSV HEADER;