[英]Show result of pgAgent step
How setup pgAgent step so Result
or Output
show the number of rows processed on my function? 如何设置pgAgent步骤以使
Result
或Output
显示在函数上处理的行数?
my function already return the number of rows affected, but that isnt the value show in Result
. 我的函数已经返回受影响的行数,但这不是
Result
显示的值。
BEGIN
WHILE int_pending > 0 LOOP
.....
UPDATE table SET ....
GET DIAGNOSTICS int_row_count = ROW_COUNT;
int_total = int_total + int_row_count;
END LOOP;
RETURN int_total;
END;
According to source code of pgagent : 根据pgagent的源代码 :
output = stepConn->GetLastError();
...
rc = threadConn->ExecuteVoid(
wxT("UPDATE pgagent.pga_jobsteplog ")
wxT(" SET jslduration = now() - jslstart, ")
wxT(" jslresult = ") + NumToStr(rc) + wxT(", jslstatus = '") + stepstatus + wxT("', ")
wxT(" jsloutput = ") + threadConn->qtDbString(output) + wxT(" ")
wxT(" WHERE jslid=") + jslid);
pgagent stores last error of of job step execution. pgagent存储作业步骤执行的最后错误。
So, there are two ways to implement desired behaviour: 因此,有两种方法可以实现所需的行为:
use RAISE EXCEPTION
inside plpgsql function, something like this: 在plpgsql函数中使用
RAISE EXCEPTION
,如下所示:
CREATE OR REPLACE FUNCTION test_output() RETURNS VOID AS $$ DECLARE rows int := 25; BEGIN RAISE EXCEPTION 'Updated rows: %', rows; END; $$ LANGUAGE PLPGSQL;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.