Error on Dynamic csv file export using plpgsql copy to csv in a function
问题 I am trying to filter a postgresql table for rows that have a product id as a foreign key. For each product id, I need to export 1 csv each to a folder eg , prod1.csv, prod2.csv etc. I have tried to create the function below to automate this but the function is failing when I run it. Can anyone kindly assist me to fix the function or recommend a better approach? CREATE or replace FUNCTION exportdata() RETURNS SETOF record AS $$ DECLARE rec text; BEGIN FOR rec IN ( Select distinct t.products