pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: nourry@ensinfo.univ-nantes.fr
To: pgsql-sql@postgresql.org
Subject: Re: Retrieving column names and table names of a database
Date: Tue, 18 May 1999 14:52:41 +0200 (MET DST)
Message-ID: <199905181252.OAA03376@dec1.ensinfo.univ-nantes.fr> (raw)

>Hi,
>, this may sound stupid, but is there a way of retrieving the table names and >column names of a database using SQL. I know there
>is \d in psql, but I don“t know if there is something similar in SQL or if there >is a function I can call. 
>Please reply even if there is no function
>
>Thanks in advance for your help
>
>Matthias
>. 

 To retrieve the table names , use the pg_tables :
    SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%';

 To retrieve the column names , you can use the pg_attribute and
pg_type tables :
     SELECT attname , typname FROM pg_attribute , pg_type WHERE   
  typrelid=attrelid AND typname = 'banals' ;
     if your table name is 'banals' , but this will give you 6 columns that
you haven't declared : cmax,xmax,cmin,xmin,oid,ctid .

  If you want column names with its type :
      SELECT attname , opcname , atttypmod FROM pg_attribute,pg_type,
    pg_opclass WHERE attrelid=typrelid AND atttypid=opcdeftype AND 
    typname = 'banals' ;
          if your table name is 'banals' , but this will give the
column 'oid' you haven't declared

  You can find all tables names in <where you put psql>//data/base/ .

 Sorry for my english !



view thread (2+ messages)

Message-ID: <199905181252.OAA03376@dec1.ensinfo.univ-nantes.fr>
Permalink:  ../199905181252.OAA03376@dec1.ensinfo.univ-nantes.fr/
Also on:    postgresql.org/message-id/199905181252.OAA03376@dec1.ensinfo.univ-nantes.fr

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: nourry@ensinfo.univ-nantes.fr
  Subject: Re: Retrieving column names and table names of a database
  In-Reply-To: <199905181252.OAA03376@dec1.ensinfo.univ-nantes.fr>
  References: <199905181252.OAA03376@dec1.ensinfo.univ-nantes.fr>

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

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