Re: How to create a trigger

From: "Thomas F(dot) O'Connell" <tfo(at)monsterlabs(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to create a trigger
Date: 2001-05-11 14:56:39
Message-ID: 3AFBFDA7.2060208@monsterlabs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-05-11 15:13:55 Re: Problems on inserting with DBD::Pg
Previous Message Fran Fabrizio 2001-05-11 14:36:12 Trigger only firing once