I'm trying to run a query that does a
foreach of each element of an array, and then copies this to a directory with a custom named file. Here's the code I have presently:
arr varchar := array['item1','item2'];
foreach x in array arr
y := concat('C:\Outputs\output_' , x , '.csv');
copy (select * from pdtable where pdtable.area = x) to y With CSV;
However this encounters an error in the copy statment at the
to y statement. Is there an alternative way to do this?