Received: from ece.rice.edu (ece.rice.edu [128.42.4.34]) by hub.org (8.9.2/8.9.1) with ESMTP id TAA09278 for ; Fri, 9 Apr 1999 19:37:56 -0400 (EDT) (envelope-from reedstrm@rice.edu) Received: from rice.edu (wallace.ece.rice.edu [128.42.12.154]) by ece.rice.edu (8.9.0/8.9.0) with ESMTP id SAA25829 for ; Fri, 9 Apr 1999 18:37:53 -0500 (CDT) Sender: reedstrm@ece.rice.edu Message-ID: <370E8F51.EE94D7BC@rice.edu> Date: Fri, 09 Apr 1999 18:37:53 -0500 From: "Ross J. Reedstrom" Organization: NSBRI X-Mailer: Mozilla 4.06 [en] (X11; U; Linux 2.2.3-ac3 i686) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: [SQL] how to retrieve... References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit ZioBudda wrote: > > On Wed, 7 Apr 1999, Margarita Barvinok wrote: > > > > > Try in psql > > \d > > Is this right answer on your question? > > no, I need it via a query... > I want to recreate the structure of a table if I know the name of the > table. > This is in the FAQ - but the answer there is 'look at the source and see how \d tablename does it with queries' ;-) The freshly beta'd V 6.5 has a new optin '-E' (Explain?) where it will show you the queries psql uses to get at the system table stuff. I learned by poking arounf the source of pgaccess.tcl, which is included in the distribution. Here's a partial example from one of my tables: idas_proto=> \d "Teams" Table = Teams +----------------------------------+----------------------------------+-------+ | Field | Type | Length| +----------------------------------+----------------------------------+-------+ | TeamID | int4 not null | 4 | | TeamName | text | var | | TeamShortName | text | var | | TeamIDASRep | int4 | 4 | | TeamLeader | int4 | 4 | | TeamMission | text | var | | TeamDescription | text | var | | TeamImage | text | var | +----------------------------------+----------------------------------+-------+ Index: Teams_pkey idas_proto=> select attname from pg_attribute pa, pg_class pc where pa.attrelid=pc.oid and pc.relname='Teams'; attname --------------- cmax xmax cmin xmin oid ctid TeamID TeamName TeamShortName TeamIDASRep TeamLeader TeamMission TeamDescription TeamImage (14 rows) idas_proto=> -- Ross J. Reedstrom, Ph.D., NSBRI Research Scientist/Programmer Computer and Information Technology Institute Rice University, 6100 S. Main St., Houston, TX 77005