Received: from orion.SAPserv.Hamburg.dsh.de (Tpolaris2.sapham.debis.de [53.2.131.8]) by hub.org (8.9.3/8.9.3) with SMTP id NAA43902 for ; Tue, 4 Jan 2000 13:44:47 -0500 (EST) (envelope-from wieck@debis.com) Received: from debis.com by orion.SAPserv.Hamburg.dsh.de with smtp for id m125YnA-0003kGC; Tue, 4 Jan 100 19:34 MET Sender: wieck Message-ID: <38723F15.9EADB8A7@debis.com> Date: Tue, 04 Jan 2000 19:42:29 +0100 From: Jan Wieck X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.13 i686) X-Accept-Language: en MIME-Version: 1.0 To: Mitch Vincent CC: pgsql-sql@postgresql.org Subject: Re: [SQL] Triggers References: <21582.943985242@sss.pgh.pa.us> <00cc01bf56c5$03cd5e80$40ee2fd8@venux.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mitch Vincent wrote: > I'm using this funtion via a trigger to total up amounts in several fields > (and adding that value into a total field).. > > CREATE FUNCTION invoice_total_trigger() RETURNS OPAQUE AS ' > ... > > That's the function, here is the trigger. > > CREATE TRIGGER invoice_total_trigger AFTER INSERT OR UPDATE ON invoice > FOR EACH ROW EXECUTE PROCEDURE invoice_total_trigger(); > > It works for updating but not when you insert a new row. Am I doing it > wrong? I wonder why it works on UPDATE at all, it shouldn't. It is an AFTER ROW trigger and thus, the changed row you return should get ignored. Use BEFORE INSERT instead. But that it works on UPDATE indicates some bug somewhere. What release, OS, etc. are you using? Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #========================================= wieck@debis.com (Jan Wieck) #