CREATE OR REPLACE FUNCTION admin.copy_haritapaftabin(IN p_path text, IN p_filename_prefix text, OUT file_and_path text)
RETURNS text AS
$BODY$
DECLARE
qry TEXT;
BEGIN
file_and_path := RTRIM(p_path,'/') || '/' || p_filename_prefix || '_' || to_char(CURRENT_TIMESTAMP, 'YYYY-MM-DD-HH-MI'::text) || '.csv';
qry := FORMAT('COPY (select * from harita.paftabin) TO %L CSV HEADER',file_and_path);
EXECUTE qry;
END;
$BODY$
LANGUAGE plpgsql VOLATILE STRICT SECURITY DEFINER
COST 100;
select komutu tabloyu csv olarak dışarı alır. job yapılabilir
SELECT admin.copy_haritapaftabin('e:\YEDEK\VT\csv','haritapaftabin');