X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E533FDB02C for ; Tue, 22 Nov 2005 11:28:33 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 63423-03 for ; Tue, 22 Nov 2005 15:28:36 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from matrix.gatewaynet.com (host2.dynacom.ondsl.gr [62.103.35.210]) by svr1.postgresql.org (Postfix) with ESMTP id 07242DB022 for ; Tue, 22 Nov 2005 11:28:26 -0400 (AST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id jAMGPoKc024826; Tue, 22 Nov 2005 18:25:50 +0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id jAMGPo89024822; Tue, 22 Nov 2005 18:25:50 +0200 Date: Tue, 22 Nov 2005 18:25:50 +0200 (EET) From: Achilleus Mantzios To: "Leif B. Kristensen" cc: pgsql-sql@postgresql.org Subject: Re: Triggers In-Reply-To: <200511221543.47979.leif@solumslekt.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/194 X-Sequence-Number: 23445 O Leif B. Kristensen έγραψε στις Nov 22, 2005 : > I'm trying to understand triggers. I have read the documentation in the > manual as well as the few pages in the Douglas book about the subject, > but I don't see how to implement a trigger that simply updates a > 'last_edit' date field in my 'persons' table whenever I do an insert or > update into my 'participants' table; that is a trigger that basically > does an "UPDATE persons SET 'last_edit' = NOW() WHERE persons.person_id > = participants.person_fk". Is that even possible? > smth like: foodb=# CREATE or REPLACE FUNCTION upd_dad() RETURNS "trigger" AS ' foodb'# BEGIN foodb'# UPDATE dad set lastedit=now() where id=new.dadid; foodb'# RETURN new; foodb'# END; foodb'# ' foodb-# LANGUAGE plpgsql; CREATE FUNCTION foodb=# CREATE TRIGGER upd_dad_tg AFTER INSERT OR UPDATE ON kid FOR EACH ROW EXECUTE PROCEDURE upd_dad(); -- -Achilleus