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 1gdLk2-0004Ew-O3 for pgsql-general@arkaria.postgresql.org; Sat, 29 Dec 2018 21:01:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gdLk1-0006jl-2W for pgsql-general@arkaria.postgresql.org; Sat, 29 Dec 2018 21:01:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdLk0-0006je-I5 for pgsql-general@lists.postgresql.org; Sat, 29 Dec 2018 21:01:52 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdLjx-0002HX-GZ for pgsql-general@lists.postgresql.org; Sat, 29 Dec 2018 21:01:50 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id E0A1721305; Sat, 29 Dec 2018 16:01:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 29 Dec 2018 16:01:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=n nMvpwFqbf82Gh/W0UfQHzrcxWYRdEY9yvwnyBB2KBM=; b=2Yg6MdxBfFzwP7WAx mOd7frx2DkTmPnVpE6C3YzmLfLX8jJfFUAhBVRm2iBp2zDkf9uWNfpQ1U32vFCG3 v56TES4c8DwLxT7WrWG0roovICsS9cwzdVm/92ypgAFN/kIFC10VM5+BRjLV9U0K GQ8x69iGVAn9+rI5J2s0FQjwTK1XEFnGYSKsIA0Ab3eTzAEV5l2c1/eXc5W0hRtX HACRbk50U+OIpU1mxBL7Ncsgah2YiXisMkOi9BAIt/sBLljwhDi7tO89TLCGAYx0 aqrhDgRgZZhClzPUANhQpBMqqeJ93voyIW558R4DD5HeCkVDiDHvP0JsoaA4C/oj oH10Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=nnMvpwFqbf82Gh/W0UfQHzrcxWYRdEY9yvwnyBB2K BM=; b=ia6CXmvq6+EQUXDj5u7ld17ZwfucXmjhrIP1TTQuCB9qKnAcMqlKd86Ix fidSm+MwxjvuFzi23C/rGKflLLINDVyrmRk2AW5vCRPXwKpIS+Oulic4pgfYr2Gp vFhDtWnxTRUxCelglWyT1+elQ180EMBVq2wO7zZWpamjGbyhaal3c/HQ/0RMUuTG FShvIIjGpRfyubk5jQwk0syhSGMDTK/fjV3j4IcI1RsyCtX9GABenVsNjlqjj6yV /3pBFwtIQPZS4CmpeS5EUyVBCyD84nhuJsULLxqG6dlMub2zrdoxIgRUZAs92HWS jwK9mp5faL1f/d/8CNvyRKt51Dvsw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrtdekgddugeeiucdltddurdegtdekrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhht necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesth ejredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepphhoshhtghhrvg hsqhhlrdhorhhgnecukfhppeejuddrvdduvddrudefgedrfeenucfrrghrrghmpehmrghi lhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 24470E4666; Sat, 29 Dec 2018 16:01:48 -0500 (EST) Subject: Re: In which session context is a trigger run? To: Mitar Cc: pgsql-general@lists.postgresql.org References: <0a13079f-27c7-68dd-b52f-af9385185d2b@aklaver.com> From: Adrian Klaver Message-ID: <68399335-b0b6-31e3-ea16-afe2c0373892@aklaver.com> Date: Sat, 29 Dec 2018 13:01:47 -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 11:44 PM, Mitar wrote: > Hi! > > On Fri, Dec 28, 2018 at 9:36 PM Adrian Klaver 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