1
drop function if exists f(float);
create function f(x float)
returns float
language plpgsql
as $$
begin
return 1/x;
exception
when others then
raise notice 'oops';
return 0::float;
end;
$$;
このPL/pgSQLの機能を考えると、select f(0);
コード22012例外、タイプdivision_by_zero
につながることは明らかです。これを知ると、exception
句のセレクタをwhen division_by_zero then ...
に絞り込むことができます。
ただし、任意の関数については、どのようにエラータイプを取得できますか? raise notice error.code
のようなものはありますか?