Re: Disabling triggers in a transaction - Mailing list pgsql-general

From Net Virtual Mailing Lists
Subject Re: Disabling triggers in a transaction
Date
Msg-id 20050309060841.19330@mail.net-virtual.com
Whole thread Raw
In response to Disabling triggers in a transaction  (Jay Guerette <jayguerette@gmail.com>)
Responses Re: Disabling triggers in a transaction
List pgsql-general
>It is the only known way to control triggers though it isn't regularly
>tested by the developers.


I think I've come up with another way.. I posted this recently, but did
not get any feedback on it so I'm not sure how dumb it is...  It is
working really great for me though....


All I did was added an extra column to my table (I called it
"batch_process").  Then in
the trigger do something like (in whichever function you are calling):

IF NEW.batch_update IS NOT NULL AND NEW.batch_update = ''t'' THEN
  NEW.batch_process := NULL;
  RETURN NULL;
END IF;
.. whatever the rest of transaction is


Then when doing an insert, just:

INSERT INTO table (..., batch_process) VALUES (..., 't') when you want the
trigger not to fire...

Or an update:

UPDATE TABLE table SET ...., batch_process = 't' ....


I'm not sure sure how to make it work on a function called from a delete
trigger though.. ;-(

- Greg


pgsql-general by date:

Previous
From: "Uwe C. Schroeder"
Date:
Subject: Re: PostgreSQL still for Linux only?
Next
From: Tom Lane
Date:
Subject: Re: PostgreSQL still for Linux only?