From: James Olin Oden <joden@lee.k12.nc.us>
To: James Andrews <jamesa@darkplaces.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] How do I get the list of table names in db
Date: Wed, 5 Aug 1998 11:49:00 -0400
Message-ID: <81Aug4.103807edt.35713@gateway.lee.k12.nc.us> (raw)
References: <3.0.32.19980805033804.006a9c30@pop.darkplaces.com>
> I need to know how to get a list of table names that exist in a particular
> database using Pg. I know how to do it command line, but I need my scripts
> to be able to do it for error checking, and I haven't found a single doc on
> it.
>
> -james
Well, here is one way. In your script issue the command:
psql -c "\d" -o filename database_name
depending on your scripting language you may need to wrap the command around
some other command such as:
system ("psql -c \"\\d\" -o filename database_name");
in perl. Now with this approach your script will then need to read in the file
created by the -o switch. If your in perl you could do something like:
open(COMMAND, "psql -c \"\\d\" database_name|")
while (<COMMAND>)
{
print $_;
<YOUR CODE GOES HERE>
}
to not generate a file, and read in the standard output of the psql command.
In the the Korn shell you could do:
psql -c "\d" database_name| while read LINE
do
echo $LINE
<YOUR CODE GOES HERE>
done
Hope this helps...james
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: joden@lee.k12.nc.us, jamesa@darkplaces.com
Subject: Re: [SQL] How do I get the list of table names in db
In-Reply-To: <81Aug4.103807edt.35713@gateway.lee.k12.nc.us>
References: <3.0.32.19980805033804.006a9c30@pop.darkplaces.com> <81Aug4.103807edt.35713@gateway.lee.k12.nc.us>
* 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