From: Tom Lane <tgl@sss.pgh.pa.us>
To: Matt Andrews <mattandrews@massey.com.au>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Mapping view columns to their source columns
Date: Wed, 25 Sep 2019 00:54:08 -0400
Message-ID: <22840.1569387248@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPeDGQ6KrAL8+8myKWorcj02G05otgMrSgOzi9axemaZf=cScA@mail.gmail.com>
References: <CAPeDGQ6KrAL8+8myKWorcj02G05otgMrSgOzi9axemaZf=cScA@mail.gmail.com>
Matt Andrews <mattandrews@massey.com.au> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, mattandrews@massey.com.au
Subject: Re: Mapping view columns to their source columns
In-Reply-To: <22840.1569387248@sss.pgh.pa.us>
References: <CAPeDGQ6KrAL8+8myKWorcj02G05otgMrSgOzi9axemaZf=cScA@mail.gmail.com> <22840.1569387248@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox