Re: [SQL] how to retrieve... - Mailing list pgsql-sql

From Ross J. Reedstrom
Subject Re: [SQL] how to retrieve...
Date
Msg-id 370E8F51.EE94D7BC@rice.edu
Whole thread Raw
In response to Re: [SQL] how to retrieve...  (ZioBudda <michel@michel.enter.it>)
List pgsql-sql
ZioBudda wrote:
> 
> On Wed, 7 Apr 1999, Margarita Barvinok wrote:
> 
> >
> > Try in psql
> > \d <table name>
> > 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., <reedstrm@rice.edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005


pgsql-sql by date:

Previous
From: ZioBudda
Date:
Subject: Re: [SQL] how to retrieve...
Next
From: Will Benton
Date:
Subject: aggregate functions and varchar type