Re: Trigger Function return values

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org, achambers(at)mcna(dot)net
Subject: Re: Trigger Function return values
Date: 2011-03-23 00:38:18
Message-ID: 201103221738.19017.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-03-23 01:25:24 Re: constraint partition issue
Previous Message Helen_Yelluas 2011-03-23 00:31:00 constraint partition issue