X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 58B3A5280B for ; Wed, 8 Jun 2005 18:50:36 -0300 (ADT) 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 55876-06 for ; Wed, 8 Jun 2005 21:50:27 +0000 (GMT) Received: from mxsf26.cluster1.charter.net (mxsf26.cluster1.charter.net [209.225.28.226]) by svr1.postgresql.org (Postfix) with ESMTP id 98EC15289E for ; Wed, 8 Jun 2005 18:50:20 -0300 (ADT) Received: from mxip19a.cluster1.charter.net (mxip19a.cluster1.charter.net [209.225.28.149]) by mxsf26.cluster1.charter.net (8.12.11/8.12.11) with ESMTP id j58LoLLx031589 for ; Wed, 8 Jun 2005 17:50:21 -0400 Received: from pc-68-118-180-13.will.ct.charter.com (HELO [192.168.116.102]) (68.118.180.13) by mxip19a.cluster1.charter.net with ESMTP; 08 Jun 2005 17:50:22 -0400 X-IronPort-AV: i="3.93,184,1115006400"; d="scan'208"; a="1122236686:sNHT16147202" Message-ID: <42A7681C.9060007@NarrowPathInc.com> Date: Wed, 08 Jun 2005 17:50:20 -0400 From: Keith Worthington Reply-To: KeithW@NarrowPathInc.com Organization: Narrow Path, Inc. User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: David Hofmann Cc: pgsql-sql@postgresql.org Subject: Re: Rule References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.058 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/120 X-Sequence-Number: 21721 >>>David wrote: >>> >>>What I want to do is setup some kind of rule so that whenever a s_data >>>field is updated, that the time_stamp gets update to the current time/date. >> >> Normally you want to do that with a before trigger rather than a rule. > > Ok, I have no knowledge of Tiggers except what I just read in the docs > section. Look like I need to make a procudure then call it with a trigger. > > Is there a better location for Tigger/Procudure Examples. The trigger > seems fairly, however I got lost in the procudure part. > > David David, Here is a trigger function that I wrote for storing audit information. Whether or not a query provides the user and/or timestamp this procedure sets them. Naturally you will need to modify them for your data model. CREATE OR REPLACE FUNCTION interface.tf_audit_data() RETURNS "trigger" AS $BODY$ BEGIN -- Set the user name. SELECT * FROM session_user INTO NEW.audit_user; -- Set the timestamp. NEW.audit_timestamp := ('now'::text)::timestamp(6) with time zone; -- Send the modified record down the pipe. RETURN NEW; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; ALTER FUNCTION interface.tf_audit_data() OWNER TO postgres; GRANT EXECUTE ON FUNCTION interface.tf_audit_data() TO postgres; GRANT EXECUTE ON FUNCTION interface.tf_audit_data() TO public; CREATE TRIGGER tgr_audit_data BEFORE INSERT OR UPDATE ON sales_order.tbl_line_item FOR EACH ROW EXECUTE PROCEDURE interface.tf_audit_data(); -- Kind Regards, Keith