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: Fri, 28 Dec 2018 15:25:30 -0800
Message-ID: <c1654f3a-410d-ae7a-8e8d-b3e7a6eee810@aklaver.com> (raw)
In-Reply-To: <CAKLmikMyiYHzVtwVvuvU=nPJZFJcMNL9Qsc+3o6q=C9g8hH4Dw@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>

On 12/28/18 12:59 PM, Mitar wrote:
> Hi!
> 
> On Fri, Dec 28, 2018 at 12:57 PM Adrian Klaver
> <adrian.klaver@aklaver.com> wrote:
>>> CREATE OR REPLACE FUNCTION pg_temp.my_function()
>>
>> And it does what?
> 
> Copies/transforms data from posts into posts_temp.
> 
>>> When a row is added to "posts" table outside of my session, function
>>> "my_function" is called, but it seems it cannot access "posts_temp"
>>> table. It seems that "my_function" is called in the session of the
>>
>> Temp tables can not be seen by other sessions.
> 
> Sure, but why is a temporary function used as a temporary trigger made

There is no such thing as a temporary trigger.

> from my session not run inside my session? Then it could see a
> temporary table made in my session.

Except that is not what your OP stated:

"And I add it to a regular table as a trigger:

CREATE TRIGGER posts_insert AFTER INSERT ON posts REFERENCING NEW
TABLE AS new_table FOR EACH STATEMENT EXECUTE FUNCTION
pg_temp.my_function();

When a row is added to "posts" table outside of my session, function
"my_function" is called, but it seems it cannot access "posts_temp"
table."

So are you talking about another case now?

> 
> 
> Mitar
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (14+ messages)  latest in thread

Message-ID: <c1654f3a-410d-ae7a-8e8d-b3e7a6eee810@aklaver.com>
Permalink:  ../c1654f3a-410d-ae7a-8e8d-b3e7a6eee810@aklaver.com/
Also on:    postgresql.org/message-id/c1654f3a-410d-ae7a-8e8d-b3e7a6eee810@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: <c1654f3a-410d-ae7a-8e8d-b3e7a6eee810@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>

* 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