Re: Functions and Triggers

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Cedar Cox <cedarc(at)visionforisrael(dot)com>
Cc: Norbert Schollum <schollum(at)equinux(dot)de>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Functions and Triggers
Date: 2001-03-27 09:59:05
Message-ID: 200103270959.EAA26759@jupiter.jw.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Cedar Cox wrote:
>
> CREATE FUNCTION lastupdated() RETURNS opaque AS '
> begin
> new.last_updated := CURRENT_TIMESTAMP;
> return new;
> end;
> ' LANGUAGE 'plpgsql';
>
> CREATE TRIGGER trigname BEFORE INSERT OR UPDATE on tblname
> FOR EACH ROW EXECUTE PROCEDURE lastupdated();
>
> Note: you could use now() instead of CURRENT_TIMESTAMP
>
> Note2: on a BEFORE trigger you must return new or old. If you return null
> the statement will be aborted. (?)

If you return NULL from a BEFORE trigger the action on that
particular row will be silently suppressed.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sean Weissensee 2001-03-27 13:10:42 Upgrading from 6.2 to 7
Previous Message Jan Wieck 2001-03-27 09:43:15 Re: all views in database broken at once