Given this pl/pgSQL function
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;
$$;
it is clear that select f( 0 ); will result in an code 22012 exception, type division_by_zero. Knowing this I can narrow down the selector of the exception clause to when division_by_zero then ....
However, for arbitrary functions, how can I obtain the error type? Is there anything like, say, raise notice error.code?