From dbmss@yahoo.com Wed Nov 25 01:18:11 1998 Received: from send201.yahoomail.com (send201.yahoomail.com [205.180.60.131]) by hub.org (8.9.1/8.9.1) with SMTP id UAA27258 for ; Tue, 24 Nov 1998 20:18:11 -0500 (EST) (envelope-from dbmss@yahoo.com) Message-ID: <19981125012036.13087.rocketmail@send201.yahoomail.com> Received: from [207.172.60.196] by send201.yahoomail.com; Tue, 24 Nov 1998 17:20:36 PST Date: Tue, 24 Nov 1998 17:20:36 -0800 (PST) From: dbms dbms Subject: Question about schema To: pgsql-sql@postgreSQL.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Hi all, Can I use SQL to get info about a table which can be gotten by doing a \d [table name] under psql? Rdbms _________________________________________________________ DO YOU YAHOO!? Get your free @yahoo.com address at http://mail.yahoo.com From reina@nsi.edu Wed Nov 25 01:48:05 1998 Received: from nsi.edu (amethea.nsi.edu [198.133.185.9]) by hub.org (8.9.1/8.9.1) with ESMTP id UAA29524 for ; Tue, 24 Nov 1998 20:48:05 -0500 (EST) (envelope-from reina@nsi.edu) Received: from nsi.edu (IDENT:reina@bigred.nsi.edu [204.128.156.214]) by nsi.edu (8.9.1/8.9.1) with ESMTP id RAA17209; Tue, 24 Nov 1998 17:47:41 -0800 (PST) Sender: reina@nsi.edu Message-ID: <365B623C.2B03BB2E@nsi.edu> Date: Tue, 24 Nov 1998 17:49:48 -0800 From: "G. Anthony Reina" Organization: The Neurosciences Institute X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.0.34 i686) MIME-Version: 1.0 To: dbms dbms , reina@nsi.edu, "pgsql-questions@postgresql.org" Subject: Re: [SQL] Question about schema References: <19981125012036.13087.rocketmail@send201.yahoomail.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit If you just want to know what your table looks like, try: select * from pg_class; To just get the class names, try select relname from pg_class; I'm pretty sure that you can execute this from psql c-commands. -Tony From tgl@sss.pgh.pa.us Wed Nov 25 16:03:31 1998 Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6]) by hub.org (8.9.1/8.9.1) with ESMTP id LAA05755 for ; Wed, 25 Nov 1998 11:03:31 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id KAA28221; Wed, 25 Nov 1998 10:55:33 -0500 (EST) To: dbmss@yahoo.com cc: pgsql-sql@hub.org Subject: Re: Question about schema In-reply-to: Your message of Tue, 24 Nov 1998 23:00:24 -0500 (EST) <199811250400.XAA10150@hub.org> Date: Wed, 25 Nov 1998 10:55:33 -0500 Message-ID: <28219.912009333@sss.pgh.pa.us> From: Tom Lane dbmss@yahoo.com writes: > Can I use SQL to get info about a table > which can be gotten by doing a > \d [table name] > under psql? psql uses plain old SQL queries to extract the info it presents with \d; it's not doing anything you couldn't do too. Read the source code for psql (src/bin/psql/psql.c) to see what queries are used to produce the various sorts of \d reports. For example, the particular case of "\d table" is handled in the routine named tableDesc, and from looking at that you can see that it constructs a primary query like this: SELECT a.attnum, a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid ORDER BY attnum Looks like there are additional queries made to get the values of field defaults and so forth. All this stuff is kept in the system tables, and you can query those tables with ordinary queries. regards, tom lane