Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gczCF-0006Dj-A7 for pgsql-general@arkaria.postgresql.org; Fri, 28 Dec 2018 20:57:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gczCD-00030Y-Ui for pgsql-general@arkaria.postgresql.org; Fri, 28 Dec 2018 20:57:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gczCC-00030R-8v for pgsql-general@lists.postgresql.org; Fri, 28 Dec 2018 20:57:29 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gczC4-0003V5-55 for pgsql-general@lists.postgresql.org; Fri, 28 Dec 2018 20:57:27 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id A1D36221B0; Fri, 28 Dec 2018 15:57:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 28 Dec 2018 15:57:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=5 JPcmSfmlKiK9vIzXVOTntvQJ6HevnFsW6YF9CjChWs=; b=Fm8yFPSQasPUOYeKc ly7CTD3bRd3XsCJxCeNMP4CcR016MQfw4CBjQJeOFdiBKiTxXrmYTyxZU70EoJ3h WAxB1Cf/4cwtY3QoCnK+11jeD9WOmVnptzVPCjcJAX9Fh9nFo9gSOMu/RSaCg12m S1OTcjCG+hNU6rpKv0YqLj+7hnDrUOD8Q3XU0RlmJ/kDMYrhhk4tF6Si3LgPSpaq 7Mn6d7SeVrNRYkJFwd1AGkke7i/7eIIjyc80Q2CAadqW1tnqBByo0hXWDv4sIEbG S85v1haMhJbHtpbQnS7fOfrDWkZEFB9UXfZUbzelKJEy/w2iiXGAxugtcc5rIrM4 RriZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=5JPcmSfmlKiK9vIzXVOTntvQJ6HevnFsW6YF9CjCh Ws=; b=c9k5o6Z05yMK6InSgxrFwWGEitHheT4Jb86Mq2iGrHDCBgrQu4nm6aazK StgbALdiFSsJhh7C4JqoUO+xGPRBdct/Yu1I8XIHOykuTUGsxIxwIJOIBCvEYXZ7 pRBOS0WRX1dfVmo7/Mi6TpYK4peUCqI5I8mpNjFNGpFQY1DINdwpbAoMvT8gsvNO H+wJ9enT2jjG2kKCEwQGsyO7TzyrehDMwSH99/qRWDDymVlahQgzDaa0FtCCrvDO miWo5EhAqE8y57GjAy80JOw6S98L17usLI8EI9O/H/1+64llxfLHIFTfM+8pWNkG MUkk6tnSDVwZ4nZSREjlIGjn1oMpA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrtdehgddugeehucdltddurdegtdekrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhht necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesth ejredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucfkphepjedurddvuddvrddufeegrd efnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhl rghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id C4C3CE4665; Fri, 28 Dec 2018 15:57:16 -0500 (EST) Subject: Re: In which session context is a trigger run? To: Mitar , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Fri, 28 Dec 2018 12:57:15 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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