Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 将数据从postgres保存到文件txt或csv_Postgresql_Psql_Pgadmin - Fatal编程技术网

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

Postgresql 将数据从postgres保存到文件txt或csv,postgresql,psql,pgadmin,Postgresql,Psql,Pgadmin,请告诉我在执行update语句时是否可以保存文件的任何数据 我在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 =

请告诉我在执行update语句时是否可以保存文件的任何数据

我在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(如果成功),但我不知道如何做,以及如何将Status的值返回到文件?我不想复制所有表。

do language plpgsql
$$
布尔金
更新胶片
设置长度=1000
其中标题=‘学院恐龙’;
如果找到了
复制(选择格式('Title=%s,Status=%s','Academy Diolan','Success'))
到“文件路径”;
enf if;
结束;
$$;

格式
和文本替换仅适用于需要使用变量的情况。否则,只需
(选择“Title=Academy diology,Status=Success”)

整个PL/pgSQL块完全不需要。你可以直接运行更新,这会更快,因为没有无用的
select count(*)
被执行。@a_horse_与_no_name我知道这只是一个例子,我不知道如何记录成功执行此块时的信息。在我的实际块中,我只检查了一行。如果没有,我想记录信息:状态:文件不存在问题我完成了路径“C:\Desktop”,在windows终端中运行是否有问题?像这样:psql-h localhost-p 5432-U user-d db-f C:\Desktop\script.sql在这个文件中我有一个脚本,我把输出文件放在那里,但我得到了错误字符,编码“UTF8”时有字节序列0xc5 0xbc,编码“WIN1252”时没有等效字符我正在谷歌上搜索,但仍然没有任何帮助,除非我能够在有linux基础的服务器上运行它。现在,我仍然无法在windows上复制:错误:语法错误在或接近\copy(选择'Title=aaaa,Status=wwwww'我正在尝试这个:\copy(选择'Title=aaaa,Status=success')到“C:\Users\Desktop\output.csv”;复制服务器上的读写文件。“文件路径”应该是服务器进程看到的服务器上的本地路径。它不能引用终端上的位置。顺便说一句,plpgsql脚本和psql命令不是一回事。好的,明天我将在我的postgres服务器上运行此脚本,该服务器在l上工作伊努克斯,我希望它能起作用:)今天我用psql运行这个脚本,因为我在Wndows上创建了一个postgres服务器,我希望当我像这样在windows终端上运行psql-h localhost-p 5432-U user-d db-f C:\Desktop\script.sql时,它会起作用。我知道windows中的psql中运行exist\copy for,这可以起作用,但是\copy以all表为例,我想知道具体的信息记录到文件。