> Hello
>
> you have to parse a sqlerrm variable
That's one way to do that. Another - more complex but more correct in many
cases is using two separate blocks.
BEGIN
... do stuff involving constraint A
EXCEPTION
WHEN unique_violation THEN ...
END;
BEGIN
... do stuff involving constraint
Hello
you have to parse a sqlerrm variable
CREATE OR REPLACE FUNCTION public.test(a integer, b integer)
RETURNS void
LANGUAGE plpgsql
AS $function$
begin
insert into foo values(a,b);
exception when unique_violation then
raise notice '% %', sqlerrm, sqlstate;
end;
$function$
postgres=#
Hello!
I have a question about catching exceptions.
If I write a plpgsql function like this
begin
do stuff;
exception
when X then
when Y then
...
end;
If the "do stuff" part can result in two different unique_violation
exception (having two unique constraints), how can I detect w