From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | webbj2(at)Scranton(dot)edu |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Select list of table names for particular DB |
Date: | 2005-12-19 06:01:22 |
Message-ID: | 20051219060122.GA90550@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sun, Dec 18, 2005 at 12:18:04PM -0500, webbj2(at)Scranton(dot)edu wrote:
> I am trying to figure out how to get (select) a list of all the names of
> the tables in a database when given the name of the database. ie.,
> Select table_name from ??? where datbase name = "XYZ";
Except for a few shared tables each database has its own catalogs,
so to get a list of a database's tables you have to connect to that
database.
> I can easily select names of tables in current db like this:
> SELECT datname FROM pg_database;
That doesn't list tables, it lists databases.
> But, if I want to retrieve all table names for a different db, I can
> not figure it out.
Connect to the other database and query its catalogs. You could
abstract this with dblink and a view.
> I looked at doc for pg_class and can find a relation name but no ID#.
> I thought maybe I could find a database ID related to table IDs, but
> can not determine what a databases classID might be or what a tables
> ID might be.
A relation's oid is in the pg_class.oid system column (not shown
in the documentation for pg_class but described in "System Columns"
in the "Data Definition" chapter). Databases aren't shown in
pg_class.
--
Michael Fuhr
From | Date | Subject | |
---|---|---|---|
Next Message | A. Kretschmer | 2005-12-19 07:42:25 | Re: sequences in transaction blocks |
Previous Message | Michael Fuhr | 2005-12-19 05:48:40 | Re: One DB not backed up by pg_dumpall |