Lock inside trigger

From: Josué Maldonado <josue(at)lamundial(dot)hn>
To: pgsql-general(at)postgresql(dot)org
Subject: Lock inside trigger
Date: 2004-03-16 21:11:59
Message-ID: 40576D9F.5040506@lamundial.hn
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello list,

I have pl/pgsql trigger that before insert a details table it must
update a column in other table, the trigger have this code:

CREATE OR REPLACE FUNCTION public.tg_ecproc_insert()
RETURNS trigger AS
' DECLARE
salproc numeric(12,2);
BEGIN
select coalesce(prvsalproc,0) into salproc from
prvdor where prvcode=new.ecp_provcode;
-- How do I prevent someone else to change
-- prvdor.prvsalproc during this transaction
if new.ecp_dc=''C'' then
new.ecp_saldo = salproc - new.ecp_valor;
else
new.ecp_saldo = salproc + new.ecp_valor;
end if;
update prvdor set prvsalproc = new.ecp_saldo
where prvcode=new.ecp_provcode ;
-- Here I should be able to unlock the row on
-- prvdor table
return new;
END;
'
LANGUAGE 'plpgsql' VOLATILE;

Does postgresql automatically handle the lock on tables updated from
within a trigger? or what's the must appropiate way to get this done?

Thanks in advance,

--

Josué Maldonado

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joan Picanyol 2004-03-16 21:22:22 rule as on insert to view with multiple fk referencing the same table
Previous Message Bill Moran 2004-03-16 20:23:48 Re: L doesn't seem to be working in to_char()