Any way to SELECT a list of table names?

Started by Eric Freemanabout 22 years ago5 messagesgeneral
Jump to latest
#1Eric Freeman
ejf7@hotmail.com

Is there any way in Postgres to SELECT a list of table names from inside of
a C program using ECPG?
Something similar to SELECT current_user that will give you all of the
tables in the database you are connected to.

_________________________________________________________________
High-speed users�be more efficient online with the new MSN Premium Internet
Software. http://join.msn.com/?pgmarket=en-us&page=byoa/prem&ST=1

#2Thomas Kellerer
spam_eater@gmx.net
In reply to: Eric Freeman (#1)
Re: Any way to SELECT a list of table names?

Eric Freeman schrieb:

Is there any way in Postgres to SELECT a list of table names from inside
of a C program using ECPG?
Something similar to SELECT current_user that will give you all of the
tables in the database you are connected to.

I guess you are looking for the information stored in pg_tables:

http://www.postgresql.org/docs/current/static/view-pg-tables.html

Thomas

#3scott.marlowe
scott.marlowe@ihs.com
In reply to: Eric Freeman (#1)
Re: Any way to SELECT a list of table names?

On Sat, 10 Jan 2004, Eric Freeman wrote:

Is there any way in Postgres to SELECT a list of table names from inside of
a C program using ECPG?
Something similar to SELECT current_user that will give you all of the
tables in the database you are connected to.

If you are running 7.4 and have the information_schema you can use that to
find out just about anything.

#4Ken Godee
ken@perfect-image.com
In reply to: scott.marlowe (#3)
Re: Any way to SELECT a list of table names?

On Sat, 10 Jan 2004, Eric Freeman wrote:

Is there any way in Postgres to SELECT a list of table names from inside of
a C program using ECPG?
Something similar to SELECT current_user that will give you all of the
tables in the database you are connected to.

Not sure if this is what you're trying to do but.......

"SELECT tablename FROM pg_tables where tablename not like 'pg_%'"

Will get a list of tables in the db you're connected to.

#5Chris Travers
chris@travelamericas.com
In reply to: scott.marlowe (#3)
Re: Any way to SELECT a list of table names?

From: "Ken Godee" <ken@perfect-image.com>

Not sure if this is what you're trying to do but.......

"SELECT tablename FROM pg_tables where tablename not like 'pg_%'"

Will get a list of tables in the db you're connected to.

You can do that, but if by any chance, the pg_catalog schema changes, you
may find your app broken. The pg_catalog schema is not really intended to
be a client interface, so if you go that way, you may want to wrap it in a
function :-)

Now, if you are using PostgreSQL 7.4, use this query instead:

select table_name, table_schema from information_schema.tables where
table_schema NOT IN ('pg_catalog', 'information_schema');

Best wishes,
Chris Travers