Re: Disable Trigger for session only

From: gmb <gmbouwer(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Disable Trigger for session only
Date: 2015-06-30 08:31:37
Message-ID: 1435653097868-5855854.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message drunken 2015-07-01 08:10:50 [C#] File Upload to PostgreSQL
Previous Message gmb 2015-06-30 07:17:47 Re: Disable Trigger for session only