Write to a file from RAISE NOTICE in postgresql

我是研究僧i 提交于 2021-01-28 14:59:38

问题


I have one sample function in postgresql and it raises a notice.

Sample function -

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?

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'

回答1:


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.



来源:https://stackoverflow.com/questions/32566641/write-to-a-file-from-raise-notice-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!