postgres将异常错误插入表中

时间:2018-04-30 12:41:28

标签: postgresql plpgsql postgresql-9.4

如何在下面的查询中的表格上插入异常消息

 do $$ 
   begin
    Select (2 / 0) 

 exception when others then 

    RAISE INFO 'Error Name:%',SQLERRM;

    RAISE INFO 'Error State:%', SQLSTATE;

    Insert into TB_ERRORLOG(msg) values('Error =' || SQLERRM || SQLSTATE);
  END;

 $$ language 'plpgsql';

1 个答案:

答案 0 :(得分:0)

以下是固定的声明。

 DO $$ 
  BEGIN
    SELECT (2 / 0); 

EXCEPTION WHEN others THEN 

RAISE INFO 'Error Name:%',SQLERRM;

RAISE INFO 'Error State:%', SQLSTATE;

INSERT INTO TB_ERRORLOG(msg) VALUES ('Error =' || SQLERRM || SQLSTATE);
 END;

 $$ language plpgsql;