I have procedure and it works well.
CREATE OR REPLACE FUNCTION f_dynamic_copy(_tbl text = 'tmp1')
RETURNS void AS
$func$
DECLARE
_filename VARCHAR;
BEGIN
_filename := '/tmp/' || random() || '.csv';
EXECUTE format($$COPY (select id, 1, 1, 1 from my_first_table) TO %L$$, _filename);
EXECUTE format($$COPY my_second_table FROM %L$$, _filename);
END
$func$ LANGUAGE plpgsql;
But I want to delete temporary files created in this procedure. How to do it?
plperlufunction, or cron jobs to clean up old files.