Re: triggers

From: Eric B(dot)Ridge <ebr(at)tcdi(dot)com>
To: gearond(at)cvc(dot)net
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: triggers
Date: 2003-02-25 21:15:09
Message-ID: 385A5C3A-4906-11D7-ADA1-0003937E3354@tcdi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday, February 25, 2003, at 03:17 PM, Dennis Gearon wrote:

> are 'before' triggers or 'after' triggers more common?

it depends on what you want to do. In many situations you'll need both.

>
> Why?

Before triggers are most useful when you need to change the value of a
column *before* it is updated/inserted (using the NEW table). Or if
you want to completely deny the operation (by RETURNing NULL from the
trigger function).

After triggers are useful when you need to modify table B based on the
fact that something successfully happened in table A. You can
guarantee that the after triggers only happen if the before trigger and
the actual action successfully completed.

>
> What's the benefits, problems with each?
>
> Can a function in a trigger lock a table? Or is it just sessions that
> can lock a table?

Yes, they can lock tables.

eric

In response to

  • triggers at 2003-02-25 20:17:27 from Dennis Gearon

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ivan 2003-02-25 21:22:01 simple questions
Previous Message daniel alvarez 2003-02-25 20:46:47 Peculiarities of using OIDs as primary key