Обсуждение: Make Trigger run after completion of ENTIRE transaction

Поиск
Список
Период
Сортировка

Make Trigger run after completion of ENTIRE transaction

От
"Henry Ortega"
Дата:
This maybe more of a theoretical question, can you actually make a Trigger run
after completion of the entire transaction?
 
Here's what I have:
LOG
user   |    startdate       |       enddate
 
enddate is getting updated by a trigger (on insert or update).
 
I have the following transaction:
BEGIN;
Insert into LOG(user,startdate) values('jdoe','2006-08-13');
Insert into LOG(user,startdate) values('jdoe','2006-08-14');
Insert into LOG(user,startdate) values('jdoe','2006-08-15');
Insert into LOG(user,startdate) values('jdoe','2006-08-16');
Insert into LOG(user,startdate) values('jdoe','2006-08-17');
........... another 20-30 more inserts..........
COMMIT;
 
The trigger actually runs on each Insert and therefore slows down the
Insert quite a bit.
 
My question is, can you tell the trigger to run after Commit?

Re: Make Trigger run after completion of ENTIRE transaction

От
Markus Schaber
Дата:
Hi, Henry,

Henry Ortega wrote:
> This maybe more of a theoretical question, can you actually make a
> Trigger run
> after completion of the entire transaction?
[...]
> ........... another 20-30 more inserts..........

Which frontend do yu use? Maybe COPY is better than insert.

> The trigger actually runs on each Insert and therefore slows down the
> Insert quite a bit.

This sounds like the trigger itsself could be optimized a bit, or does
some work that is not best suited to be in a trigger.

> My question is, can you tell the trigger to run after Commit?

I assume the trigger has to do some integrity checking work?

Could you reformulate it as foreign key or check constraints? (you may
even call a complex plpgsql function from the check constraint). Most
constraint checks can be deferred to the end of the transaction, see the
docs for more details.

HTH,
Markus

-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in Europe! www.ffii.org
www.nosoftwarepatents.org