简体   繁体   English

显示pgAgent步骤的结果

[英]Show result of pgAgent step

How setup pgAgent step so Result or Output show the number of rows processed on my function? 如何设置pgAgent步骤以使ResultOutput显示在函数上处理的行数?

在此处输入图片说明

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: 因此,有两种方法可以实现所需的行为:

  • patch source code to implement your feature, recompile, install and use this custom version 修补源代码以实现您的功能,重新编译,安装和使用此自定义版本
  • 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM