Received: from rhea.worldonline.nl (rhea.worldonline.nl [195.241.48.139]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5T7cNa82507 for ; Fri, 29 Jun 2001 03:38:25 -0400 (EDT) (envelope-from feite.brekeveld@osiris-it.nl) Received: from osiris-it.nl (vp222-16.worldonline.nl [195.241.222.16]) by rhea.worldonline.nl (Postfix) with ESMTP id 31AEA36D45; Fri, 29 Jun 2001 09:38:09 +0200 (MET DST) Message-ID: <3B3C4231.862D1299@osiris-it.nl> Date: Fri, 29 Jun 2001 10:54:09 +0200 From: Feite Brekeveld X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.14-15mdksmp i686) X-Accept-Language: en MIME-Version: 1.0 To: Andy Samuel Cc: pgsql-general@postgresql.org Subject: Re: Trigger References: <000501c1005d$c8547020$0100a8c0@foserver> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200106/1202 X-Sequence-Number: 11836 Andy Samuel wrote: > How do I create a trigger on a table if a certain row is updated ? > For example, a table called DefaultValue with : > ModuleId char(10), > FieldId char(10), > DefVal char(3) > > If I update the table 'update DefaultValue set defval='OFF' where > FieldId='MODULESTATUS' then it will fire the event. Here is an example of one I use CREATE FUNCTION "update_seqno" ( ) RETURNS opaque AS ' BEGIN new.seqno = nextval(''cdrseqno''); new.status = ''U''; return new; END;' LANGUAGE 'plpgsql'; CREATE TRIGGER "updseq_no" BEFORE INSERT ON "accounting" FOR EACH ROW EXECUTE PROCEDURE "update_seqno" (); seqno and status are attributes of the accounting-table that do not get set by the insert statement I use, so the trigger provides the sequence number from the defined sequence 'cdrseqno' and sets a default status on it. You can define triggers on [ BEFORE/AFTER ] [ INSERT/DELETE/UPDATE ] . This all is documented in the docs that come with PostgreSQL. Pay attention to the double ' when you create functions/triggers. Regards, Feite > > > Thank you in advance > Andy > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html -- Feite Brekeveld feite.brekeveld@osiris-it.nl http://www.osiris-it.nl