title: How to zip CSV files through stored function in postgres
body: <p>I am generating a few CSV files using COPY statements from postgres in a stored function.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION "public"."create_csv" () RETURNS INT AS
  $$
  BEGIN
      EXECUTE format('COPY (SELECT * FROM test) TO %L DELIMITER '','' CSV HEADER', '/tmp/test.csv');
      EXECUTE format('COPY (SELECT * FROM test2) TO %L DELIMITER '','' CSV HEADER', '/tmp/test2.csv');
  RETURN 0;
  END;
  $$
  LANGUAGE 'plpgsql' SECURITY DEFINER
  </code></pre>
  
  <p>This function is called from a parent one, after the execution of that I want to zip the generated CSV files into a zip file, how can I accomplish this using stored functions in the data base? Is there a way to do so using plpgsql? Or should i use plpythonu language?
  Postgres version 9.6.
  Thanks!</p>