Re: After insert trigger question - Mailing list pgsql-general

From mmiranda@americatel.com.sv
Subject Re: After insert trigger question
Date
Msg-id 76E0DAA32C39D711B6EC0002B364A6FA0440F8E6@amsal01exc01.americatel.com.sv
Whole thread Raw
In response to After insert trigger question  (mmiranda@americatel.com.sv)
Responses Re: After insert trigger question
List pgsql-general
>PostgreSQL 8.0 introduced PL/pgSQL exception handlers.

>http://www.postgresql.org/docs/8.0/interactive/plpgsql-control-structures.h
tml#PLPGSQL-ERROR-TRAPPING

>Regardless of whether the trigger is BEFORE or AFTER, an untrapped
>error will abort the insert.

>CREATE FUNCTION trigfunc() RETURNS trigger AS '
>DECLARE
>    i  integer;
>BEGIN
>    i := NEW.x / 0;
>    RETURN NULL;
>END;
>' LANGUAGE plpgsql;

>CREATE TABLE foo (x integer);

>CREATE TRIGGER footrig_after AFTER INSERT ON foo
>  FOR EACH ROW EXECUTE PROCEDURE trigfunc();

>INSERT INTO foo VALUES (123);
>ERROR:  division by zero
>CONTEXT:  PL/pgSQL function "trigfunc" line 4 at assignment

>SELECT * FROM foo;
> x
>---
>(0 rows)

>--
>Michael Fuhr
>http://www.fuhr.org/~mfuhr/


So, the answer is:  "double check every operation and use exeption handlers"
What about performance, if its a matter of choice between after or before
insert, what perform better?
thanks


pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: After insert trigger question
Next
From: Michael Fuhr
Date:
Subject: Re: After insert trigger question