EXCEPTION in pl/pgsql

Started by Craig Brydenover 20 years ago2 messagesgeneral
Jump to latest
#1Craig Bryden
postgresql@bryden.co.za

Hi All

What is the syntax if I want to use the exception clause in a pl/pgsql
function, but am not looking for a particular error. Kind of like a "any
error" type thing.

some thing like:

CREATE OR REPLACE FUNCTION func1(p_Param1 int4)
RETURNS int4
AS
$$

DECLARE
v_Var1 int4;

BEGIN
[Statements]
RETURN 1;

EXCEPTION
WHEN <any_error> THEN
ROLLBACK;
RETURN -1;
END;
$$ LANGUAGE 'plpgsql' volatile;

What should I replace <any_error> with?

Thanks

#2Hannes Dorbath
light@theendofthetunnel.de
In reply to: Craig Bryden (#1)
Re: EXCEPTION in pl/pgsql

On 19.07.2005 20:56, Craig Bryden wrote:

What is the syntax if I want to use the exception clause in a pl/pgsql
function, but am not looking for a particular error. Kind of like a "any
error" type thing.

35.7.5. Trapping Errors
http://www.postgresql.org/docs/8.0/interactive/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

"The special condition name OTHERS matches every error type except
QUERY_CANCELED."