Re: Re: How to create a trigger - Mailing list pgsql-general

From Joseph Shraibman
Subject Re: Re: How to create a trigger
Date
Msg-id 3B005787.2A21E212@selectacast.net
Whole thread Raw
In response to How to create a trigger  ("Laurent Duperval" <lduperval@microcelli5.com>)
List pgsql-general
See
http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=10

"Thomas F. O'Connell" wrote:
>
> > create trigger date_update before update on mytable
> >     for each statement execut procedure [procedure that inserts a date
> > for me in the update_date column]
> >
> > So what would I be doing for the portion in brackets?
>
> at that point you need a function.
>
> check out the CREATE FUNCTION syntax in the docs
> (http://www.postgresql.org/idocs/index.php?sql-createfunction.html).
>
> for what you were talking about, it seems like something as simple as
>
> create function trigger_before_update_mytable() returns opaque as '
> begin
>         new.update_date = now();
>         return new;
> end;
> ' as language 'plpgsql';
>
> would work.
>
> then your last line of the trigger statement would be:
>
> for each statement execut procedure trigger_before_update_mytable();
>
> good luck.
>
> -tfo
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--
Joseph Shraibman
jks@selectacast.net
Increase signal to noise ratio.  http://www.targabot.com

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Problem with referential integrity and inherited tables in 7.1.1
Next
From: Martín Marqués
Date:
Subject: Re: PostgreSQL in Comparison to mySQL