agora inbox for postgres@postgres.berkeley.edu  
help / color / mirror / Atom feed
From: Mark Costlow <cheeks@swcp.com>
To: stewart@oec.com
Cc: postgres@postgres.Berkeley.EDU
Subject: gleaning the database structure
Date: Thu, 4 Aug 1994 18:20:53 -0600
Message-ID: <199408050020.SAA26157@kitsune.swcp.com> (raw)
In-Reply-To: <Pine.3.89.9408041735.A4358-0100000@outland.oec.com>


On Thu, 4 Aug 1994 17:57:57 -0400 (EDT),
Stewart Allen <stewart@oec.com> said:

Stewart>  Is there a simple set of queries which would provide basic
Stewart>  table/column structure information within a database? 

Here are a few queries that I worked up to do this.  I built these by
looking at the code for pg_relshow (in the contributed software that comes
with Postgres).  


------------------------------------

To get the list of databases:

retrieve (pg_database.datname)

------------------------------------

Get the list of tables in the current database:

retrieve (pg_class.relname) where pg_class.relname !~ "^pg_"

------------------------------------

Get the list of attributes for a table ("mailees" in this example):

retrieve (FieldNum = a.attnum, FieldName = a.attname, Type = t.typname)
    from c in pg_class, a in pg_attribute, t in pg_type
    where c.relname = "mailees"
      and c.oid = a.attrelid
      and a.attnum > 0
      and t.oid = a.atttypid
    sort by FieldNum using <

------------------------------------

>>Chx
--
Mark Costlow
Southwest Cyberport - Public Access Internet in Albuquerque, NM
Email: cheeks@swcp.com   Voice: 505-271-0009

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"

   If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: postgres@postgres.berkeley.edu
  Cc: cheeks@swcp.com, stewart@oec.com
  Subject: Re: gleaning the database structure
  In-Reply-To: <199408050020.SAA26157@kitsune.swcp.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox