In which session context is a trigger run?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Mitar <mmitar(at)gmail(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: In which session context is a trigger run?
Date: 2018-12-31 05:58:58
Message-ID: CAKFQuwaKsCiTVYEmB2ubDAPaXw5fubF=JvtGx5Vi1WuQseQcKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday, December 28, 2018, Mitar <mmitar(at)gmail(dot)com> wrote:
>
> On Fri, Dec 28, 2018 at 9:36 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andres Freund 2018-12-31 06:07:50 Re: ERROR: found multixact XX from before relminmxid YY
Previous Message Chuck Martin 2018-12-30 23:17:08 Re: getting pg_basebackup to use remote destination