从 postgres 将数据保存到文件 txt 或 csv

Save data to file txt or csv from postgres

请问我执行更新语句时是否可以保存文件的任何数据?

我在 postgres pgadmin / psql 中执行这个函数

do
$$
declare 
    nr int;
    status varchar(100);
begin
    select count(*) into nr from film where title = 'Academy Dinosaur';
    if nr = 1 then
        update film
        set length = 1000
        where title = 'Academy Dinosaur';
        status := 'Success';
        end if;
end;$$

并且我想写入文件(如果更新已成功执行),如下所示: Title = title, Status = Succes(如果成功)但我不知道该怎么做以及如何 return 状态值到文件?我不想复制所有 table.

do language plpgsql
$$
brgin
 update film
    set length = 1000
  where title = 'Academy Dinosaur';
 if FOUND then
   copy (select format('Title = %s, Status = %s', 'Academy Dinosaur', 'Success')) 
     to 'path-to-your-file';
 enf if;
end;
$$;

format 和文本替换仅适用于您想要使用变量的情况。否则只是 (select 'Title = Academy Dinosaur, Status = Success')