Thread: How to find names of tables in a database?

How to find names of tables in a database?

From
Valerie Mates
Date:
Hi -- I've been dabbling in PostgreSQL on and off for a few months now.  At
this point I can get it to do a number of neat things, but I've run into
one that is a stumper.

I'm looking for a way that my Perl program can look up the names of the
tables in a database.  Is there a way to do this?  I've looked through the
documentation on the PostgreSQL website, but didn't find any way to do
this.  It seems like there must be a query like "SELECT table_names FROM
my_database" to do this, but if there is, I haven't found it yet.

(My apologies if this has been discussed recently.  I was on this mailing
list for a while, but have been off it for a month or so.)

Thanks for any help you can offer!

-Valerie Mates

    -------------------------------------------------------------------
      Valerie Mates  *  Web Developer  *  http://www.valeriemates.com
               valerie@cyberspace.org  *  (734) 995-6716
    -------------------------------------------------------------------



Re: [GENERAL] How to find names of tables in a database?

From
Simon Drabble
Date:
On Wed, 14 Oct 1998, Valerie Mates wrote:

> Hi -- I've been dabbling in PostgreSQL on and off for a few months now.  At
> this point I can get it to do a number of neat things, but I've run into
> one that is a stumper.
>
> I'm looking for a way that my Perl program can look up the names of the
> tables in a database.  Is there a way to do this?  I've looked through the
> documentation on the PostgreSQL website, but didn't find any way to do
> this.  It seems like there must be a query like "SELECT table_names FROM
> my_database" to do this, but if there is, I haven't found it yet.

select relname from pg_class where relname not like 'pg_%';

will give you all user-defined tables.


Simon.


>
> (My apologies if this has been discussed recently.  I was on this mailing
> list for a while, but have been off it for a month or so.)
>
> Thanks for any help you can offer!
>
> -Valerie Mates
>
>     -------------------------------------------------------------------
>       Valerie Mates  *  Web Developer  *  http://www.valeriemates.com
>                valerie@cyberspace.org  *  (734) 995-6716
>     -------------------------------------------------------------------
>
>
>

--
  There are three kinds of people in this world: Those who can count,
     and those who can't.

   Simon Drabble                     mailto:madlather@syspac.com
   http://fiddletrudge.dyn.ml.org/
   KreatAPayj           --        KAP2/login.html
   LizardCam            --        LizardCam/LizCam.html