Thread: Trigger Function return values
Hi, How is the return value of a trigger function defined in plpgsql used? I can't find anything in the documentation but some of the examples return NULL, and others return something like NEW. It seems that if the return statement is omitted, an error occurs when the trigger is fired. -- Andy Chambers
On Mar 22, 2011, at 4:12 PM, Andy Chambers wrote: > How is the return value of a trigger function defined in plpgsql used? I can't find > anything in the documentation but some of the examples return NULL, and others return > something like NEW. <http://www.postgresql.org/docs/9.0/static/trigger-definition.html> -- Scott Ribe scott_ribe@elevated-dev.com http://www.elevated-dev.com/ (303) 722-0567 voice
On Tuesday, March 22, 2011 3:12:56 pm Andy Chambers wrote:
> Hi,
>
> How is the return value of a trigger function defined in plpgsql used? I
> can't find
> anything in the documentation but some of the examples return NULL, and
> others return
> something like NEW.
>
> It seems that if the return statement is omitted, an error occurs when the
> trigger is
> fired.
From here:
http://www.postgresql.org/docs/9.0/interactive/plpgsql-trigger.html
Row triggers:
"Row-level triggers fired BEFORE can return null to signal the trigger manager to skip the rest of the operation for this row (i.e., subsequent triggers are not fired, and the INSERT/UPDATE/DELETE does not occur for this row). If a nonnull value is returned then the operation proceeds with that row value. Returning a row value different from the original value of NEW alters the row that will be inserted or updated. "
Statement triggers:
"The return value of a row-level trigger fired AFTER or a statement-level trigger fired BEFORE or AFTER is always ignored; it might as well be null. However, any of these types of triggers might still abort the entire operation by raising an error. "
--
Adrian Klaver
adrian.klaver@gmail.com