在 postgresql 中从 RAISE NOTICE 写入文件 [英] Write to a file from RAISE NOTICE in postgresql
问题描述
我在 postgresql 中有一个示例函数,它引发了一个通知.
I have one sample function in postgresql and it raises a notice.
示例函数-
CREATE OR REPLACE FUNCTION raise_test() RETURNS TEXT AS
$body$
DECLARE
retStr TEXT;
BEGIN
SELECT current_timestamp into retStr;
RAISE NOTICE '%', retStr ;
RETURN retStr;
END;
$body$
LANGUAGE plpgsql;
有什么办法可以更新上面的函数,让整个通知保存到一个文件中?
Is there any way to update above function so that the entire notice stored into a file?
就像我点击call raise_test();"在我的特定位置,我将有一个 out.txt 并打印了整个通知.
Like if I hit "call raise_test();" and in my specfic location I 'll have one out.txt with the entire notice printed.
附注.我尝试将通知插入到临时表中,然后使用 -
PS. I hv tried to insert the notice in to a temp table then use -
COPY (select * from temp) TO '\home\pgsql\out.txt'
推荐答案
回复取决于您的可能性.您无法使用通常的工具来完成这项工作.有两种可能性 - 首先 - 使用一些 PostgreSQL 扩展,可以创建文件并写入文件,如 Orafce 或您可以编写自己的 C 扩展来使用 PostgreSQL 日志钩子 - 和然后你可以做你想做的.
The reply depends on your possibilities. You cannot to do this work with usual tools. There are two possibilities - first - use some PostgreSQL extensions with possibility to create file and write to file like Orafce or you can write own C extension that will use PostgreSQL log hook - and then you can do what you want.
这篇关于在 postgresql 中从 RAISE NOTICE 写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!