I have a table in my database that contains data with three columns: id, name, and notes. The notes column contains unstructured text data that I want exported for each row as its own text file. This means if I had 5 rows in my table, then I would export 5 .txt files. Here is my attempt so far:
do $$ declare arow record; files varchar; begin for arow in select id, name, note from multi_text loop files := '/tmp/'||arow.id||'_'||arow.name||'.txt'; COPY (select note from multi_text where id = arow.id) TO files (FORMAT CSV); end loop; end; $$;
Currently, there is a
ERROR: syntax error at or near "files". I am using PostgreSQL in pgadmin. Any help is much appreciated!