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 1gdeNx-0004PB-V9 for pgsql-general@arkaria.postgresql.org; Sun, 30 Dec 2018 16:56:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gdeNw-0002Zw-L5 for pgsql-general@arkaria.postgresql.org; Sun, 30 Dec 2018 16:56:20 +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 1gdeNv-0002Zo-Ef for pgsql-general@lists.postgresql.org; Sun, 30 Dec 2018 16:56:20 +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 1gdeNs-0003Jr-Gq for pgsql-general@lists.postgresql.org; Sun, 30 Dec 2018 16:56:18 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 8482D21B0B; Sun, 30 Dec 2018 11:56:15 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sun, 30 Dec 2018 11:56:15 -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=E PNp7xckvsAw+QgONJzRhetH9XnhXZQH4SASyKm6b58=; b=q23/H091mSwork8Rh Vy1cypPWin6wrE//gm0pnWk1ESs+ekgxHu0ITZYslloHT+vsODKhXwlLe/7mNv+6 jV8HW4GMZyTkgCRTrOsD1IqoNaNKIoON8EMnjz5pN8AwgiBuPfmKL/EDhMjHrPmD ZpxD3uRXMjSvmvX+93XwXnop3ERX7VK8IL6m7NOfRXS1JmWj/RfOnsP5igPMv8pY 6TMp+0wrC9s3d5tLQC1DW/1YSvaVZptCXEjhP+QszatA7XCSW3l1p7zlIVftu9l/ JF9+zAfxb1ZxvPuHj5scX/X5yGDjkTrzb87Z0N7XNWQrGNWMeo5eDkYGILLuy9iv QdLrw== 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=EPNp7xckvsAw+QgONJzRhetH9XnhXZQH4SASyKm6b 58=; b=hl9UR7Eo/1JUf3YwNUwanrnRUHJAhdFS0tObtDQcWhTgEOFeaIlkghcf3 nSyFeyB5yDaj3NZxUI+YiwU+yBS7INNCrPTgry9u0j9jdJ7wFFNv6uh+e39j7edU UOFblUXo4L38T1UB8myUQpmgs67AepHwf9vQVoP4yWJIo3mc6hhhEgxmapUYAy1F BFyzcSQ2b+8DMxVo9CBJTcD67RRPC436pxD1NAAiPVwbGuQ1OwiO8LOrgCq07/XU m4vlr0qaF54q93BIPTZjbka1me3N2BoLFkwm6yApcAvR8NJKXu6zDeHPCzhTRRjS RQiHIdr+zLHnv/Mmjbh6+2arlBSug== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledruddtgdelieculddtuddrgedtkedrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeehnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecukfhppeejuddrvdduvddrudefgedrfe enucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgr vhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 6677E10085; Sun, 30 Dec 2018 11:56:14 -0500 (EST) Subject: Re: In which session context is a trigger run? To: "Peter J. Holzer" , pgsql-general@lists.postgresql.org References: <0a13079f-27c7-68dd-b52f-af9385185d2b@aklaver.com> <68399335-b0b6-31e3-ea16-afe2c0373892@aklaver.com> <20181230110811.gvcmvjxcnx4vpqgl@hjp.at> From: Adrian Klaver Message-ID: <6b3fc29a-e458-70e2-3b43-cfb98a7fbc69@aklaver.com> Date: Sun, 30 Dec 2018 08:56:13 -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: <20181230110811.gvcmvjxcnx4vpqgl@hjp.at> Content-Type: text/plain; charset=windows-1252; 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/30/18 3:08 AM, Peter J. Holzer wrote: > On 2018-12-29 13:01:47 -0800, Adrian Klaver wrote: >> On 12/28/18 11:44 PM, Mitar wrote: >>> 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. > > Is there a "not" missing in this sentence? Otherwise I don't understand > what you mean and suspect you have have misunderstood what Mitar wants. I will agree I have no idea what Mitar wants, as the examples to date have not included enough information. That is why I asked for more information. > > As I understand it, what Mitar wants can't work because it clashes with > the concepts of "sessions" and "transactions". Hence the links to the sections of the documentation that explain that, on the assumption that might help. > > Each session executes transactions sequentially, and the changes > effected by any transaction become visible to other sessions only after > the transaction committed. > > If I understood Mitar correctly he wants the trigger to execute in the > session where it was declared, not in the sessio where the statement was > executed that triggered the trigger. There is the additional hitch that the trigger is being declared to use a temporary function that is defined in an alias schema pg_temp. > > So we have two sessions A and B. there is a permanent table P and a > temporary table T in session A. The trigger on P with a temporary > function) was declared in session A, and we execute an insert statement > in session B. > > Assuming session A is currently idle (otherwise we would have to block > until the current transaction in A commits or rolls back), we start a > new transaction in A which executes the trigger. This would see the > temporary table in session A. > > But since the transaction in session B hasn't yet committed, it wouldn't > see the data that the insert statement has just inserted. Since the > point of an after insert trigger is usually to do something with this > new data, that would make the trigger useless. > > hp > > -- Adrian Klaver adrian.klaver@aklaver.com