pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Mitar <mmitar@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: In which session context is a trigger run?
Date: Sat, 29 Dec 2018 13:01:47 -0800
Message-ID: <68399335-b0b6-31e3-ea16-afe2c0373892@aklaver.com> (raw)
In-Reply-To: <CAKLmikNq72rSKXj2EcoDKESCtmx2xxYDhfvFk2ZJ3MMDA5drGg@mail.gmail.com>
References: <CAKLmikO=2kTnVpR2sjr-hTW6BW8pZwRhynVL=QZ5LnhO4jXEiw@mail.gmail.com>
	<ce1edeb5-e62e-9bc0-395c-0ebed0fcef9f@aklaver.com>
	<CAKLmikMyiYHzVtwVvuvU=nPJZFJcMNL9Qsc+3o6q=C9g8hH4Dw@mail.gmail.com>
	<c1654f3a-410d-ae7a-8e8d-b3e7a6eee810@aklaver.com>
	<CAKLmikONKsJihvYuNSboy7yGCav+-kHOgGJR8xLxksq6hbCxuw@mail.gmail.com>
	<0a13079f-27c7-68dd-b52f-af9385185d2b@aklaver.com>
	<CAKLmikNq72rSKXj2EcoDKESCtmx2xxYDhfvFk2ZJ3MMDA5drGg@mail.gmail.com>

On 12/28/18 11:44 PM, Mitar wrote:
> Hi!
> 
> 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? Could there be a
> way to get trigger to run in the session where it was declared?

Because it is where the temporary table is declared that is important. 
If you want a more definitive answer then you will need to provide more 
information, in the form of:

1) The definition for pg_temp.my_function().

2) A step by step accounting of where the objects are created, in what 
sessions and what order.


> 
> And yes, global temporary tables would be another approach to solve
> this. But being able to set the session could be another, no? Or are
> sessions linked to OS processes PostgreSQL is using and this is why
> triggers run based on the session in which a change on the table was
> made?

Take a look at:

https://www.postgresql.org/docs/11/mvcc.html

https://www.postgresql.org/docs/11/trigger-definition.html


> 
> 
> Mitar
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (14+ messages)  latest in thread

Message-ID: <68399335-b0b6-31e3-ea16-afe2c0373892@aklaver.com>
Permalink:  ../68399335-b0b6-31e3-ea16-afe2c0373892@aklaver.com/
Also on:    postgresql.org/message-id/68399335-b0b6-31e3-ea16-afe2c0373892@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, mmitar@gmail.com
  Subject: Re: In which session context is a trigger run?
  In-Reply-To: <68399335-b0b6-31e3-ea16-afe2c0373892@aklaver.com>
  References: <CAKLmikO=2kTnVpR2sjr-hTW6BW8pZwRhynVL=QZ5LnhO4jXEiw@mail.gmail.com> <ce1edeb5-e62e-9bc0-395c-0ebed0fcef9f@aklaver.com> <CAKLmikMyiYHzVtwVvuvU=nPJZFJcMNL9Qsc+3o6q=C9g8hH4Dw@mail.gmail.com> <c1654f3a-410d-ae7a-8e8d-b3e7a6eee810@aklaver.com> <CAKLmikONKsJihvYuNSboy7yGCav+-kHOgGJR8xLxksq6hbCxuw@mail.gmail.com> <0a13079f-27c7-68dd-b52f-af9385185d2b@aklaver.com> <CAKLmikNq72rSKXj2EcoDKESCtmx2xxYDhfvFk2ZJ3MMDA5drGg@mail.gmail.com> <68399335-b0b6-31e3-ea16-afe2c0373892@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox