pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mitch Vincent <mitch@venux.net>
To: pgsql-sql@postgreSQL.org
Subject: Triggers
Date: Tue, 4 Jan 2000 10:04:35 -0500
Message-ID: <00cc01bf56c5$03cd5e80$40ee2fd8@venux.net> (raw)
References: <21582.943985242@sss.pgh.pa.us>

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




view thread (34+ messages)  latest in thread

Message-ID: <00cc01bf56c5$03cd5e80$40ee2fd8@venux.net>
Permalink:  ../00cc01bf56c5$03cd5e80$40ee2fd8@venux.net/
Also on:    postgresql.org/message-id/00cc01bf56c5$03cd5e80$40ee2fd8@venux.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mitch@venux.net
  Subject: Re: Triggers
  In-Reply-To: <00cc01bf56c5$03cd5e80$40ee2fd8@venux.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox