Re: REPOST: How to determine the table a query or a views columns come from?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Frank Church <pgsql(at)adontendev(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: REPOST: How to determine the table a query or a views columns come from?
Date: 2006-03-07 11:13:59
Message-ID: 20060307111359.GD31738@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Mar 07, 2006 at 10:38:29AM +0000, Frank Church wrote:
> Quoting Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>
> Can this info be obtained by querying the system tables,
> especially in the case of views? I am using 'scripting' languages and using C
> will be quite awkward.

Well, Tom suggests the PQftable() and PQftablecol() functions which are
exported by libpq and should be available in your favourite scripting
language whenever you execute the query. If not, you should probably
fix that.

If you really feel like digging through the catalogs you should
probably start with pg_rewrite. If you look carefully, under the
targetlist node there are a number of TARGETENTRY nodes. Within that
there are the fields "resorigtbl" and "resorigcol".

Note this is going straight through compatability and out the other
side. There is no guarentee that any of these fields exist in any
version, I'm just looking at 7.4.7 here.

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Guido Neitzer 2006-03-07 11:17:12 Re: Question about index usage
Previous Message A. Kretschmer 2006-03-07 11:11:28 Re: Logging seq scans