Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eggVW-0004nL-6E for pgsql-hackers@arkaria.postgresql.org; Wed, 31 Jan 2018 00:44:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eggVU-0005Px-Sr for pgsql-hackers@arkaria.postgresql.org; Wed, 31 Jan 2018 00:44:08 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eggVU-0005Pn-Lk for pgsql-hackers@lists.postgresql.org; Wed, 31 Jan 2018 00:44:08 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eggVR-0007d6-6o for pgsql-hackers@postgresql.org; Wed, 31 Jan 2018 00:44:08 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 9496D20D79; Tue, 30 Jan 2018 19:44:03 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Tue, 30 Jan 2018 19:44:03 -0500 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-sender:x-me-sender:x-sasl-enc; s=fm1; bh=LBKxnz FL1LOtTx6eILGTMLHyli2R8XqjHELKm1FrMpc=; b=R9H8S5N3JBmpL4x8Gedw0t aZ55O0sbdsaSkAhJwgBNXo78RTh9EXGOn+je11+8SFFJK48S9tob2eXpSFktDh1r Ikms0t/bXY/meU1XzXb+YpiJVlCYIunAg5BNO03eXz3vHgySyFOJVht7BcYGomh0 1DxoPa1yaqxK3sdmYqNn16ML0dthI+6yx91fOSUmMmBqLlPo+zJNb2IwFsFOvEqe rw/o92yarIfVDdHr4eVUBx+HnsgZa/+OCaTh3iFUNsF28AdjlZg0Pq7QpuLWTFF3 W/k4kz2IMuoclfnkJJ5yg6mAOh+Tg0wijYSfgkM1z/ErBo9FW67Mo2i6vuK9JURg == X-ME-Sender: Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id 39F0A7E3FA; Tue, 30 Jan 2018 19:44:03 -0500 (EST) Subject: Re: FOR EACH ROW triggers on partitioned tables To: Amit Langote , Alvaro Herrera References: <20180123221027.2qenwwpvgplrrx3d@alvherre.pgsql> <171cb95a-35ec-2ace-3add-a8d16279f0bf@2ndquadrant.com> Cc: Pg Hackers , Simon Riggs From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <183aa6b7-468c-cc8d-12b2-aa5577bc807b@2ndquadrant.com> Date: Tue, 30 Jan 2018 19:44:02 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/30/18 04:49, Amit Langote wrote: >> If you are writing a generic >> trigger function, maybe to dump out all columns, you want to know the >> physical table and its actual columns. It's easy[citation needed] to >> get the partition root for a given table, if the trigger code needs >> that. The other way around is not possible. > > I guess you mean the root where a trigger originated, that is, ancestor > table on which an inherited trigger was originally defined. It is > possible for a trigger to be defined on an intermediate parent and not the > topmost root in a partition tree. OK, so maybe not so "easy". But this muddies the situation even further. You could be updating table A, which causes an update in intermediate partition B, which causes an update in leaf partition C, which fires a trigger that was logically defined on B and has a local child on C. Under this proposal, the trigger will see TG_RELNAME = C. You could make arguments that the trigger should also somehow know about B (where the trigger was defined) and A (what the user actually targeted in their statement). I'm not sure how useful these would be. But if you want to cover everything, you'll need three values. I think the patch can go ahead as proposed, and the other things could be future separate additions. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services