Received: from ns1.engrs.org (ns1.engrs.org [216.54.29.10]) by hub.org (8.10.1/8.10.1) with ESMTP id e86CKtB38193 for ; Wed, 6 Sep 2000 08:20:55 -0400 (EDT) Received: (from uucp@localhost) by ns1.engrs.org (8.9.3/8.9.3) id IAA18532; Wed, 6 Sep 2000 08:37:56 -0400 Received: from UNKNOWN(216.54.52.148), claiming to be "greatbridge.com" via SMTP by ns1.engrs.org, id smtpd4jmEmn; Wed Sep 6 12:37:56 2000 Message-ID: <39B6360A.8FEE705@greatbridge.com> Date: Wed, 06 Sep 2000 08:18:18 -0400 From: Chris Ryan Organization: GreatBridge LLC X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-6.1.1 i686) X-Accept-Language: en MIME-Version: 1.0 To: craig.may@s2.enthdimension.com.au CC: pgsql-sql@postgresql.org Subject: Re: Trigger References: <20000906202707.A4767@s2.enthdimension.com.au> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200009/32 Craig May wrote: > > Could someone send me a quick example of a trigger. Hope this helps. Chris Ryan <<< Clip below and execute to create example >>> -- -- FUNCTION: trigger_last_updated -- -- DESCRIPTION: -- This is a function called by the table triggers to update the last_updated -- field on insert and updates. -- create function trigger_last_updated() returns opaque as 'begin new.last_updated := now(); return new; end;' language 'plpgsql'; -- -- TABLE: test_tbl -- -- DESCRIPTION: -- A simple table to test my trigger -- create table test_tbl ( some_field varchar(10), last_updated timestamp not null default now() ); -- -- TRIGGER: trigger_insert_update_test_tbl -- -- DESCRIPTION: -- This is the trigger called on insert and updates of all the table that -- has the last_updated field. It will use the function trigger_last_updated -- The cool thing here is the function doesn't make specific reference to the -- table so you could create a different trigger for each table with the field -- last_updated and use the same function. -- create trigger trigger_insert_update_test_tbl before insert or update on test_tbl for each row execute procedure trigger_last_updated();