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.92) (envelope-from ) id 1j9GLP-000442-37 for pgsql-general@arkaria.postgresql.org; Tue, 03 Mar 2020 22:48:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9GLN-0000uP-E7 for pgsql-general@arkaria.postgresql.org; Tue, 03 Mar 2020 22:48:53 +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 1j9GLN-0000uH-4Q for pgsql-general@lists.postgresql.org; Tue, 03 Mar 2020 22:48:53 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j9GLF-0006IY-Gb for pgsql-general@postgresql.org; Tue, 03 Mar 2020 22:48:52 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 160796D9; Tue, 3 Mar 2020 17:48:43 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 03 Mar 2020 17:48:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=W tYGuDLxLyUFfqQuxaEVtMAEfyYQj8+b+mAZe0S+8IM=; b=Jx9ZiuEkj0T/GllnO UfnkYUrs0CPtmeX6GiQkx/DGiVkCQSIgK8aoz6ZEHcJinaQwLVqjQOy2QbR1OP8v mwzqde97hlmuAW48F6DoZw8qRTPZYt2h2aUIOBgNIyQiXQALVVDyAJXEdycGsQtt 0/KTsGGEeD6t8XgoRjr0d4Zgwi5144Oo16LkxSeJfZqbp42RBOgm7a72P+/xoh1m hHkRGaYemStCZsfx5HblkAwrmuHgWlcC1veZ10OJqy9d3WELAtLBQCyO9scDRzMl brGSdc31Xnl3PFPN2566JxTjzFgaZX99NWBgn/ZsGhWADMKjqFwd+AR7R7Oq2lZ9 7I+uQ== 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=fm2; bh=WtYGuDLxLyUFfqQuxaEVtMAEfyYQj8+b+mAZe0S+8 IM=; b=KYmHneZRCgxt6kWQzVGL6/+efzqe6FOeepjsYRahnsyD+GYHSze78xceq 6HEubu/ItpS3JqsOI9YvLpmP2PxfQiRFb6UT6bSEN2Gq855w37ObxzsKshVo+DNW WL4IogCoP7XOjNvxRYHYc9QTig794vOqxrudGYRo2w93PItJy//spYnm/r8kRYkv tYZT433WvYt3J4MJT4cfmpHIdXU8YlQWbvOa5jwnbsGDuAzDAbjXBvZpOcrJVpxc ApaKnwA/siWYph3DcUdL23w3E+GlESufbBKnKgVs+4MY7Z30MrhEt+Ql8WyDZohv ulOrX0aDTFkwA1mWAeK2nix6NAtlQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedruddtjedgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdrohhrghenucfkphepjedurddvuddvrdduvdelrdduleefnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrh esrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id 146C33060BD1; Tue, 3 Mar 2020 17:48:41 -0500 (EST) Subject: Re: Detecting which columns a query will modify in a function called by a trigger To: stan References: <20200302185904.GA6528@panix.com> <30c3c06e-61fa-3210-666d-1696af320a75@aklaver.com> <20200302202829.GA19161@panix.com> <20200303174248.GB5019@panix.com> <7ac6f67e-f330-1825-02e3-fa5b5a1a2940@aklaver.com> <20200303213215.GA2023@panix.com> Cc: pgsql-general From: Adrian Klaver Message-ID: <5574e3a6-2245-42c4-77fd-6e51a7a65e0c@aklaver.com> Date: Tue, 3 Mar 2020 14:48:41 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200303213215.GA2023@panix.com> 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 3/3/20 1:32 PM, stan wrote: Please reply to list also. Ccing list > On Tue, Mar 03, 2020 at 10:48:29AM -0800, Adrian Klaver wrote: >> On 3/3/20 9:42 AM, stan wrote: >>> On Mon, Mar 02, 2020 at 01:44:52PM -0700, David G. Johnston wrote: >>>> On Mon, Mar 2, 2020 at 1:28 PM stan wrote: >>>> >>>>> Envision a table with a good many columns. This table represents the "life >>>>> history" of a part on a project. Some of the columns need to be >>>>> created/modified by the engineer. Some need to be created/modified by the >>>>> purchasing agent, some of the columns need to be created by the receiving >>>>> department, some of the columns need to be created/modified by the accounts >>>>> payable department. >>>>> >>>>> Make sense? >>>>> >>>> >>>> On a theory level this design is insufficiently normalized. The fact that >>>> you are having issues and challenges working with it suggests you should >>>> seriously consider a different design, one that exhibits better >>>> normalization properties. >>>> >>>> Alternatively you might consider just removing direct access to the table >>>> and provide views and/or functions that can use normal permission grants. >>>> Add some check constraints to the table to describe and enforce the >>>> inter-field relationships that are present. >>>> >>> >>> Thanks for the input. >>> >>> I have, indeed created views that restrict the subset of columns that a >>> particular job function needs access to to the appropriate ones, but >>> unfortunately to the best of my knowledge, I cannot INSERT/UPDATE a table >>> through a view. >>> >>> Am I suffering from a lack of knowledge here? >> >> Yes: >> >> https://www.postgresql.org/docs/12/sql-createview.html >> >> Updatable Views >> > > OK, looking at that makes me think it is fairly limited. EG an Updatable > view can have on one FROM clause. Thus it by definition cannot use a JOIN. > So if I have a table with may columns, I can create a view that is a subset > of the available columns, which might be a way to address my issue. The link was for automatically updateable views. If you want to do something more involved then see: https://www.postgresql.org/docs/12/rules-views.html#RULES-VIEWS-UPDATE > > Thanks. > -- Adrian Klaver adrian.klaver@aklaver.com