Received: from smtp016.mail.yahoo.com (smtp016.mail.yahoo.com [216.136.174.113]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f1SARTx13078 for ; Wed, 28 Feb 2001 05:27:29 -0500 (EST) (envelope-from janwieck@yahoo.com) Received: from a613a.pppool.de (HELO jupiter.jw.home) (213.6.97.58) by smtp.mail.vip.sc5.yahoo.com with SMTP; 28 Feb 2001 10:27:25 -0000 X-Apparently-From: Received: (from janwieck@localhost) by jupiter.jw.home (8.9.3/8.9.3) id MAA03268; Mon, 26 Feb 2001 12:14:18 -0500 From: Jan Wieck Message-Id: <200102261714.MAA03268@jupiter.jw.home> Subject: Re: Need your help In-Reply-To: from Jie Liang at "Feb 23, 2001 01:05:44 pm" To: Jie Liang Date: Mon, 26 Feb 2001 12:14:18 -0500 (EST) CC: Jyotsna Kypa , 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: 200102/421 X-Sequence-Number: 1626 Jie Liang wrote: > e.g. > Try: > > CREATE TABLE emp ( > id int4 primary key, > empname text, > salary int4, > last_date datetime, > last_user name); > > CREATE FUNCTION emp_stamp () RETURNS OPAQUE AS > BEGIN > update emp set last_date=''now''::timestamp where id=NEW.id; > RETURN NEW; > END; > ' LANGUAGE 'plpgsql'; > > CREATE TRIGGER emp_stamp BEFORE UPDATE ON emp > FOR EACH ROW EXECUTE PROCEDURE emp_stamp(); Not sure if it works this way at all, but the update on emp table is definitely a wasted scan. And the 'now'::timestamp will be evaluated at the first function call - never again; not sure if he wanted that behaviour either. CREATE FUNCTION emp_stamp () RETURNS opaque AS ' BEGIN new.last_date := now(); RETURN new; END;' LANGUAGE 'plpgsql'; Is the correct trigger for this purpose. 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