Re: Statement level trigger clarification - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: Statement level trigger clarification
Date
Msg-id 48CE061B.1010402@gmx.net
Whole thread Raw
In response to Statement level trigger clarification  ("Chris Velevitch" <chris.velevitch@gmail.com>)
Responses Re: Statement level trigger clarification
List 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.


pgsql-general by date:

Previous
From: "Hitoshi Harada"
Date:
Subject: Re: How to check if an array is empty
Next
From: Craig Ringer
Date:
Subject: Re: declare column update expression