Re: How to get the OID of a view

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: stan <stanb(at)panix(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to get the OID of a view
Date: 2020-05-22 16:24:15
Message-ID: 30813.1590164655@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

stan <stanb(at)panix(dot)com> writes:
> I am trying to write a query to return the names, and data types of all the
> columns in a view. It has been pointed out to me that the best approach
> would be using pg_catalog. OK, so I found pg_view, which I can get the names
> of a the views from and pg_attribute which can give me the column names,
> but it looks like i need to join this on OID, and pg_table does not have
> that data.

Yeah, pg_tables is just a user-friendly view, it's not really that
useful for programmatic work. I'd look directly at pg_class and
pg_attribute for this problem.

A good way to learn what to do is to see what psql does for its
various \d commands --- if you start it with the -E option you'll
see the underlying SQL it issues. It'll likely be more complicated
than you want, but you can strip away what's not useful for you.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Charles Clavadetscher 2020-05-22 16:25:32 Re: How to get the OID of a view
Previous Message stan 2020-05-22 16:15:34 How to get the OID of a view