Re: Statement level trigger clarification

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Chris Velevitch <chris(dot)velevitch(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Statement level trigger clarification
Date: 2008-09-15 06:52:11
Message-ID: 48CE061B.1010402@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Chris Velevitch wrote:
> I'm new to triggers and I'm having difficulty in understanding how
> statement level triggers on before updates work.
>
> I have a function that sets new.last_modified := current_timestamp;
>
> If I were to define a trigger as:-
>
> CREATE TRIGGER my_trigger
> BEFORE INSERT OR UPDATE
> ON my_table
> FOR EACH STATEMENT
> EXECUTE PROCEDURE my_function();
>
> and my update statement were to update more than one row, would I be
> correct in understanding that every row the update statement touches
> will have the exact same value for last_modified?

No, this is not going to work at all. NEW and OLD are not available in
statement triggers. So your function will fail.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-09-15 07:46:48 Re: declare column update expression
Previous Message Hitoshi Harada 2008-09-15 06:50:21 Re: How to check if an array is empty