Triggers - Mailing list pgsql-sql

From Mitch Vincent
Subject Triggers
Date
Msg-id 00cc01bf56c5$03cd5e80$40ee2fd8@venux.net
Whole thread Raw
In response to Re: [SQL] NULL  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [SQL] Triggers
List pgsql-sql
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 '
BEGIN NEW.total := NEW.fee_membership + NEW.fee_logins + NEW.fee_convention +
NEW.fee_prints+ NEW.fee_hotlines + NEW.fee_postage + NEW.fee_ups +
NEW.fee_late + NEW.fee_other1 + NEW.fee_other2 + NEW.fee_other3 +
NEW.fee_pastdue; RETURN NEW;
END;
' LANGUAGE 'plpgsql';

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 need the invoice_total_trigger to run every time a row is updated or
inserted..

Thanks guys!
-Mitch



pgsql-sql by date:

Previous
From: Werner Fraga
Date:
Subject: datetime fields have '60' in seconds field
Next
From: Tom Lane
Date:
Subject: Re: [SQL] Triggers