In which session context is a trigger run? - Mailing list pgsql-general

From David G. Johnston
Subject In which session context is a trigger run?
Date
Msg-id CAKFQuwaKsCiTVYEmB2ubDAPaXw5fubF=JvtGx5Vi1WuQseQcKA@mail.gmail.com
Whole thread Raw
In response to Re: In which session context is a trigger run?  (Mitar <mmitar@gmail.com>)
Responses Re: In which session context is a trigger run?  (Mitar <mmitar@gmail.com>)
List pgsql-general
On Friday, December 28, 2018, Mitar <mmitar@gmail.com> wrote:
On Fri, Dec 28, 2018 at 9:36 PM Adrian Klaver <adrian.klaver@aklaver.com> wrote:
> When you create the temporary function it is 'pinned' to a particular
> session/pg_temp_nn. Running the trigger in another session 'pins' it to
> that session and it is not able to see the posts_temp table in the
> original session.

Yes. But why is trigger run in that other session?

Because that is the most obvious behavior.  Triggers are assumed to outlive their creating session 99.999999999% of the time, or so.
 
Could there be a
way to get trigger to run in the session where it was declared?

Doesn’t seem likely.  Maybe you can use NOTIFY/LISTEN in your temporary triggers and have your active client perform the work after being notified.

What you want is somewhat novel.  It’s worth considering whether it’s uncommon because it’s ingenious or because other techniques are more appropriate.

David J.

pgsql-general by date:

Previous
From: Chuck Martin
Date:
Subject: Re: getting pg_basebackup to use remote destination
Next
From: Andres Freund
Date:
Subject: Re: ERROR: found multixact XX from before relminmxid YY