postgresql – Exports each line of a table to a separate text file

I have a table in my database that contains data with three columns: I would, Surname, and Remarks, The Remarks This column contains unstructured text data that should be exported as a separate text file for each line. That is, if I had 5 lines in my spreadsheet, I would export 5 .txt files. Here is my previous attempt:

$$ do
to explain
Arow Record;
Files varchar;
for arow in
Select the ID, the name and the note
Files: = & # 39; / tmp / & # 39 ;|| || & # 39; & # 39 ;|| || & # 39; txt & # 39 ;;
COPY (select the note from the multiple text with id = TO files (FORMAT CSV);
end loop;
The End;

Currently there is one ERROR: syntax error on or near "files", I am using PostgreSQL in pgadmin. Any help is greatly appreciated!