Received: from smtp017.mail.yahoo.com (smtp017.mail.yahoo.com [216.136.174.114]) by mail.postgresql.org (8.11.3/8.11.1) with SMTP id f2RBkhw76586 for ; Tue, 27 Mar 2001 06:46:43 -0500 (EST) (envelope-from janwieck@yahoo.com) Received: from pd957742b.dip.t-dialin.net (HELO jupiter.jw.home) (217.87.116.43) by smtp.mail.vip.sc5.yahoo.com with SMTP; 27 Mar 2001 11:46:39 -0000 X-Apparently-From: Received: (from janwieck@localhost) by jupiter.jw.home (8.9.3/8.9.3) id EAA26759; Tue, 27 Mar 2001 04:59:05 -0500 From: Jan Wieck Message-Id: <200103270959.EAA26759@jupiter.jw.home> Subject: Re: Functions and Triggers In-Reply-To: from Cedar Cox at "Mar 26, 2001 03:44:56 pm" To: Cedar Cox Date: Tue, 27 Mar 2001 04:59:05 -0500 (EST) CC: Norbert Schollum , pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200103/548 X-Sequence-Number: 2218 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@Yahoo.com # _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com