Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jcAT6-0000jG-DQ for pgsql-general@arkaria.postgresql.org; Fri, 22 May 2020 16:24:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jcAT5-00076v-6x for pgsql-general@arkaria.postgresql.org; Fri, 22 May 2020 16:24:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jcAT4-00076n-V9 for pgsql-general@lists.postgresql.org; Fri, 22 May 2020 16:24:18 +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 1jcAT2-0005E9-T1 for pgsql-general@postgresql.org; Fri, 22 May 2020 16:24:17 +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 04MGOFV8030814; Fri, 22 May 2020 12:24:15 -0400 From: Tom Lane To: stan cc: pgsql-general@postgresql.org Subject: Re: How to get the OID of a view In-reply-to: <20200522161534.GA29059@panix.com> References: <20200522161534.GA29059@panix.com> Comments: In-reply-to stan message dated "Fri, 22 May 2020 12:15:34 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30812.1590164655.1@sss.pgh.pa.us> Date: Fri, 22 May 2020 12:24:15 -0400 Message-ID: <30813.1590164655@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk stan 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