Re: Getting a list of tables in a database with Perl

From: Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org>
To: Medi Montaseri <medi(dot)montaseri(at)intransa(dot)com>
Cc: Andrew Magnus <xanadian99(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Getting a list of tables in a database with Perl
Date: 2002-11-20 05:03:32
Message-ID: 6A54DB6E-FC45-11D6-A282-003065D0EE96@visualdistortion.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you want slightly less formatted output, you can pull some
relational database magic:
select c.relname as "Table" from pg_class c where c.relkind = 'r' and
c.relname !~ '^pg_';
will pull up a list of all user-created tables.

On Tuesday, November 19, 2002, at 04:06 PM, Medi Montaseri wrote:

> Try this from the command line....
>
> psql -c "\d"
>
> And if you want to bring this into a perl script, try
>
> perl -e '$list = `psql -c "\\d" `; print "$list\n";'
>
> A more readable version is
>
> $list = ` psql -c "\\d" `;
> print "$list \n";
>
> Or use DBI and go after pg_tables;
>
> Andrew Magnus wrote:
>
>> I would like to know how I can fetch a list of existing tables in a
>> database within a Perl script. Could someone please tell me how this
>> can be done, or, at least, a good reference to look it up? Thanks.
>>
>>
>> ----------------------------------------------------------------------
>> --
>> Do you Yahoo!?
>> Yahoo! Web Hosting
>> <http://rd.yahoo.com/hosting/mailsig/*http://webhosting.yahoo.com> -
>> Let the expert host your site
>
>
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Neil Conway 2002-11-20 05:09:17 Re: Return value in function/trigger
Previous Message Jean-Christian Imbeault 2002-11-20 03:48:03 Re: Return value in function/trigger