问题
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