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



请告诉我是否有可能保存任何数据文件当我执行更新语句

我在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;$$

和我想写的文件(如果更新被成功执行)像这样:标题=标题,状态=成功(如果成功),但我不知道如何做到这一点,如何返回状态值到文件?我不想复制所有的表

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')

最新更新