From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Mitar <mmitar@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: In which session context is a trigger run?
Date: Fri, 28 Dec 2018 12:57:15 -0800
Message-ID: <ce1edeb5-e62e-9bc0-395c-0ebed0fcef9f@aklaver.com> (raw)
In-Reply-To: <CAKLmikO=2kTnVpR2sjr-hTW6BW8pZwRhynVL=QZ5LnhO4jXEiw@mail.gmail.com>
References: <CAKLmikO=2kTnVpR2sjr-hTW6BW8pZwRhynVL=QZ5LnhO4jXEiw@mail.gmail.com>
On 12/28/18 12:47 PM, Mitar wrote:
> Hi!
>
> It seems to me that triggers on a table are run in the session context
> of the user who made a change in the table, but not of the user who
> defined the trigger?
>
> So I create a temporary function:
>
> CREATE OR REPLACE FUNCTION pg_temp.my_function()
And it does what?
>
> And a temporary table:
>
> CREATE TEMPORARY TABLE posts_temp (
> "id" CHAR(17) PRIMARY KEY,
> );
>
> 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. It seems that "my_function" is called in the session of the
Temp tables can not be seen by other sessions.
> user who modified the table, and not the user who created the function
> (pg_temp.my_function above) or the user who added the trigger.
>
> Is there a way to modify/configure this? Switch the session? Is there
> some other way that I cold define a trigger which runs for a time of
> my session and runs and interact with temporary objects inside of my
> session, when data on regular tables is modified?
>
>
> Mitar
>
--
Adrian Klaver
adrian.klaver@aklaver.com
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: <ce1edeb5-e62e-9bc0-395c-0ebed0fcef9f@aklaver.com>
References: <CAKLmikO=2kTnVpR2sjr-hTW6BW8pZwRhynVL=QZ5LnhO4jXEiw@mail.gmail.com> <ce1edeb5-e62e-9bc0-395c-0ebed0fcef9f@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