Re: How to get the OID of a view

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: stan <stanb(at)panix(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: How to get the OID of a view
Date: 2020-05-22 16:25:37
Message-ID: a213810f-5c28-43c7-ddb3-5638de7ac823@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5/22/20 9:15 AM, stan wrote:
> 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.
>
>

I'm guessing you mean pg_tables.

In any case, go straight to the source pg_class:

\dv
List of relations
Schema | Name | Type | Owner
--------+------------------+------+----------
public | tag_litem | view | postgres
public | tag_short_status | view | postgres

select oid, relname, relkind from pg_class where relname = 'tag_litem';
oid | relname | relkind
-------+-----------+---------
60558 | tag_litem | v

Where relkind = 'v' means view:

https://www.postgresql.org/docs/12/catalog-pg-class.html

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2020-05-22 16:26:03 Re: How to get the OID of a view
Previous Message Charles Clavadetscher 2020-05-22 16:25:32 Re: How to get the OID of a view