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 1iCzJh-0004uc-3q for pgsql-general@arkaria.postgresql.org; Wed, 25 Sep 2019 04:54:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iCzJf-0006AH-NB for pgsql-general@arkaria.postgresql.org; Wed, 25 Sep 2019 04:54:15 +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 1iCzJf-0006A9-BL for pgsql-general@lists.postgresql.org; Wed, 25 Sep 2019 04:54:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iCzJc-0005eG-Lw for pgsql-general@lists.postgresql.org; Wed, 25 Sep 2019 04:54:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8P4s8q8022841; Wed, 25 Sep 2019 00:54:09 -0400 From: Tom Lane To: Matt Andrews cc: pgsql-general@lists.postgresql.org Subject: Re: Mapping view columns to their source columns In-reply-to: References: Comments: In-reply-to Matt Andrews message dated "Wed, 25 Sep 2019 10:39:30 +1000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22839.1569387248.1@sss.pgh.pa.us> Date: Wed, 25 Sep 2019 00:54:08 -0400 Message-ID: <22840.1569387248@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Matt Andrews writes: > I'm trying to map view columns to their source columns using the system > catalogs and information schema, but not having much luck. It's easy to > determine which columns a view *depends *on, but not how those columns are > mapped to the columns of the view. It seems like the only way to do is this > is to somehow query the pg_node_tree in pg_rewrite.ev_call. Yeah, that's what you'd have to do. The system doesn't track this any more finely than "does the view as a whole depend on this column", partly because we don't need to and partly because it's hard to define reasonably. What do you want to do with, say, select a, b+c from tab; It gets even more interesting when you think about aggregates and other advanced features: select a, max(b) as mb from tab group by a; Any reasonable semantic analysis would have to conclude that the mb column depends on both a and b. Once you had answers to these definitional questions, you could think about analyzing the view's query tree to get the answers you want. Unfortunately, doing that from client side is not supported at all; if you try you'll find yourself maintaining a lot of messy code that we *will* break on a regular basis. It would be less hard in a backend extension, but I suspect you don't want to go there :-( regards, tom lane