Re: Disable Trigger for session only - Mailing list pgsql-sql

From gmb
Subject Re: Disable Trigger for session only
Date
Msg-id 1435653097868-5855854.post@n5.nabble.com
Whole thread Raw
In response to Re: Disable Trigger for session only  ("Greg Sabino Mullane" <greg@turnstep.com>)
List pgsql-sql
Greg Sabino Mullane wrote
> Presume you meant ENABLE here.

Yup, sorry.



Greg Sabino Mullane wrote
> Thus, you can teach the trigger you want to get disabled 
> to short-circuit if srr is set to local. Inside plpgsql it would look
> something 
> like this:
> 
> ...
> DECLARE
>   myst TEXT;
> BEGIN
>   SELECT INTO myst setting FROM pg_settings WHERE name =
> 'session_replication_role';
>   IF myst = 'local' THEN
>     RETURN;
>   END IF;
> 
> ...normal trigger code here...
> END;
> ...
> 
> Then, just issue a SET session_replication_role = 'local', and the trigger
> will 
> not do anything for that session only:

Thanks Greg, again you assisted with a neat trick.
I've definitely found that making use of session_replication_role instead is
much more efficient 
and have been using it in similar cases. 
Issue here was the one where multiple triggers exist on the table which can
by resolved using your suggestion.



--
View this message in context: http://postgresql.nabble.com/Disable-Trigger-for-session-only-tp5855658p5855854.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.



pgsql-sql by date:

Previous
From: gmb
Date:
Subject: Re: Disable Trigger for session only
Next
From: drunken
Date:
Subject: [C#] File Upload to PostgreSQL