pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow do I get the list of table names in db
3+ messages / 3 participants
[nested] [flat]
* How do I get the list of table names in db
@ 1998-08-05 07:38 James Andrews <jamesa@darkplaces.com>
0 siblings, 2 replies; 3+ messages in thread
From: James Andrews @ 1998-08-05 07:38 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] How do I get the list of table names in db
@ 1998-08-05 13:31 Maarten Boekhold <maartenb@dutepp2.et.tudelft.nl>
parent: James Andrews <jamesa@darkplaces.com>
1 sibling, 0 replies; 3+ messages in thread
From: Maarten Boekhold @ 1998-08-05 13:31 UTC (permalink / raw)
To: James Andrews <jamesa@darkplaces.com>; +Cc: pgsql-sql
On Wed, 5 Aug 1998, James Andrews wrote:
> 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.
select relname from pg_class where relkind='r' and relname !~ '^pg_'
relkind='r' gets all relations (tables) and relname!~'^pg_' excludes all
system tables.
Maarten
_____________________________________________________________________________
| TU Delft, The Netherlands, Faculty of Information Technology and Systems |
| Department of Electrical Engineering |
| Computer Architecture and Digital Technique section |
| M.Boekhold@et.tudelft.nl |
-----------------------------------------------------------------------------
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] How do I get the list of table names in db
@ 1998-08-05 15:49 James Olin Oden <joden@lee.k12.nc.us>
parent: James Andrews <jamesa@darkplaces.com>
1 sibling, 0 replies; 3+ messages in thread
From: James Olin Oden @ 1998-08-05 15:49 UTC (permalink / raw)
To: James Andrews <jamesa@darkplaces.com>; +Cc: pgsql-sql
> 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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~1998-08-05 15:49 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-08-05 07:38 How do I get the list of table names in db James Andrews <jamesa@darkplaces.com>
1998-08-05 13:31 ` Maarten Boekhold <maartenb@dutepp2.et.tudelft.nl>
1998-08-05 15:49 ` James Olin Oden <joden@lee.k12.nc.us>
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