Re: before and after triggers - Mailing list pgsql-general

From Jan Wieck
Subject Re: before and after triggers
Date
Msg-id 3E8DD5E8.EF9349C@Yahoo.com
Whole thread Raw
In response to before and after triggers  (Dennis Gearon <gearond@cvc.net>)
List pgsql-general
Dennis Gearon wrote:
>
> After reading the manual, this point didn't seem to have been made. Trigger
> fucntions are supposed to return OPAQUE, (i.e. 'void' in 'C/++' syntax). But the
> manuals also say that BEFORE triggers can return NULL to avoid the INSERT or
> UPDATE from occurring. Is this contradictory? Is that actually ONE way to avoid
> a UPDATE or INSERTION from happening?
>
> My understanding, inferred different parts of diffeent manuals, is the below,
> correct me if I'm wrong:
>
> BEFORE TRIGGERS
>         Can change the values in the NEW Tuple for:
>                 INSERTS and UPDATES.
>         Can void the action of:
>                 INSERTS and UPDATES
>                 by returning NULL. (does this kill the transaction?)

It does not abort the transaction and they can silently suppress
DELETE's too.

>         Can stop completely an action with an error message for:
>                 INSERTS,DELETES, and UPDATES
>                 by RAISING an EXCEPTION. (This DOES Kill the xaction)
>
> AFTER TRIGGERS
>         Can stop completely an action with an error message:
>                 INSERTS,DELETES, and UPDATES
>                 by RAISING an EXCEPTION. (This DOES Kill the xaction)
>         Have the advantage of seeing the final results of
>                 an action on a table before canceling it.

They only see the final result up to the row they are fired for. Since
the following is right, they would need the ability to predict the
future in an INSERT or UPDATE that affects multiple rows.

>
> ALL TRIGGERS
>         Are not DEFERRABLE in anyway. They happen immediately:
>                 AFTER or BEFORE each ROW is acted upon.


Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: before and after triggers
Next
From: nolan@celery.tssi.com
Date:
Subject: Getting consecutive sequence values