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 1gd1Vd-0007jO-AO for pgsql-general@arkaria.postgresql.org; Fri, 28 Dec 2018 23:25:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gd1Vb-0005mh-WA for pgsql-general@arkaria.postgresql.org; Fri, 28 Dec 2018 23:25:39 +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 1gd1Va-0005lx-62 for pgsql-general@lists.postgresql.org; Fri, 28 Dec 2018 23:25:39 +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 1gd1VW-0006my-2l for pgsql-general@lists.postgresql.org; Fri, 28 Dec 2018 23:25:37 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 1470021FFD; Fri, 28 Dec 2018 18:25:32 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 28 Dec 2018 18:25:32 -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=I JeCdNfXYse4e6rOt13QYA+eeANj9UvbOSAs+tXLbVE=; b=Gz6L/FN0qwWbZhzPt fxvTytu2ZQoknPW+DxPcX/MYljlrjxu+kOuC8o2hO5TuG55prdh++FdWJ3OBcAzV 0DIgxTBiZOs1NBdzY7sG87s3ggrji2f6TbkXpcdD4sptDUOQqWUSWyB6+GOZLvKF e+Pd7ZkXe5hS03RMiwXApI1B/Si16rewTgugQPVERuO0mLcjjbjr8JWXw9m+aqwx ryzsJqAdDPyehZawUpx24NAAxNtxsnOMS6ehThuZzH9PuU+ajznM+i687qOpuQr0 seStIYuyNqppMkk6NEZyyjydW8+v064FFRi120uSw9d45MiMPMVbZW2xRNiv2ArV coNgQ== 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=IJeCdNfXYse4e6rOt13QYA+eeANj9UvbOSAs+tXLb VE=; b=lkHPSJddn8MphtsD0rN5xW42LAEf7+JQVOGT6Byz9uRa32aV0QKxzQLSF IqZ3jmhWnA9IbWfEZQnqvgLbakAOH/uytYFgou/t/gvyhbdGhjeN12T0DjnQiVub HPfT36hai7QyNU30x6wslHQ0XibuIiZQ5KJDdHo5L2qYzhdYynE5RXTAByWiUa7L XytQ5hsfEaKzDdWGq3dxwZYOeIr2a0ZyIR8EemI8jO+SXNOD8GL/zbf/GeK/+kbi PMAdIqxUlF/YfX+q1yh8ug8DV85hVvhTxMJL9zuvfJrUr792Nig5swvXrOc8+SK7 lFi/i4WKFIq/tOedJxtfEr4MDVQ7A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrtdejgddtgeculddtuddrgedtkedrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk 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 74A8D100B9; Fri, 28 Dec 2018 18:25:31 -0500 (EST) Subject: Re: In which session context is a trigger run? To: Mitar Cc: pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Fri, 28 Dec 2018 15:25:30 -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:59 PM, Mitar wrote: > Hi! > > On Fri, Dec 28, 2018 at 12:57 PM Adrian Klaver > 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