他的回复:
写个简单例子:--异常记录表create table t1 (a serial,b int,c text);--存储过程,捕获除0异常create or replace function try_cal(arg int)returns int as $BODY$declareret int;begin ret := arg / (arg%2); return ret;exceptionwhen others then insert into t1(b,c) values(arg, sqlerrm); return -1;end; $BODY$language plpgsql volatile cost 1;--测试postgres=# select try_cal(1); try_cal--------- 1(1 row)postgres=# select try_cal(2); try_cal--------- -1(1 row)postgres=# select try_cal(3); try_cal--------- 3(1 row)postgres=# select try_cal(4); try_cal--------- -1(1 row)--检查异常记录数据postgres=# select * from t1; a | b | c---+---+------------------ 1 | 2 | division by zero 2 | 4 | division by zero(2 rows)