Need help with a trigger

From: Medi Montaseri <medi(at)cybershell(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Need help with a trigger
Date: 2002-02-05 06:56:47
Message-ID: 3C5F822F.169251EB@cybershell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

HI,

Can someone help me with a trigger.....

Given table invoices with ID, and Total (and bunch of other stuff) and
given
table Transactions with ID, InvoiceID, UnitCost, and Units where an
Invoice
consist of one or many Transactions. I want to write a trigger that if
UnitCost or
Units change, then visit all relevant Transactions and compute the new
Invoices.Total

So I figured I need

create function ComputeInvoiceTotal()
returns OPAQUE as '
begin
....here is where I don't know what to write...
end;'
language 'plpgsql';

create trigger transactions_trig after update on transactions
for each row execute procedure ComputeInvoiceTotal

I am a bit confused about parameter passing. Trigger Functions are
supposed to
take no arguments. that means somehow the body of the function will have
access
to the data. That would be NEW, and OLD special vars (I hope).

And I'm also confused about "for each row". What does it mean/do. I hope
its not
going to visit every row of a given table. Because the initial
update/insert has
identified which row(s).

Thanks

--
-------------------------------------------------------------------------
Medi Montaseri medi(at)CyberShell(dot)com
Unix Distributed Systems Engineer HTTP://www.CyberShell.com
CyberShell Engineering
-------------------------------------------------------------------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark kirkwood 2002-02-05 08:17:40 Re :Solaris Performance
Previous Message Stephan Szabo 2002-02-05 06:49:21 Re: Need help with a trigger