PostgreSQL: how to query the DB to get all tables in it?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Fëanor
Forum Newbie
Posts: 5
Joined: Wed Nov 19, 2003 1:04 am

PostgreSQL: how to query the DB to get all tables in it?

Post by Fëanor »

Hi,

In MySQL it is just SHOW TABLES. But what about PostgreSQL? How do I list all tables in a PostgreSQL database using a query?

I know the \d command and yes, I've searched the forum and the web.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

For a list of databases type (at the command line) 'psql -l'.
From inside the psql monitor, just try '\l'.

If you want to get database-specific attributes, such as tables, views, etc... just try typeing '\?' from the psql monitor, and you will get a list of nice functions. ('\dt' will list all tables, for example).

(from http://forums.devshed.com/t38544/s.html)
Fëanor
Forum Newbie
Posts: 5
Joined: Wed Nov 19, 2003 1:04 am

Post by Fëanor »

Thanks for the reply although it is a cross post. I mean it, it must be a query. I know the \* commands such as \d and \l, but what I want to do is something like this:

Code: Select all

<?php
$sql = "SHOW TABLES";
$result = mysql_query($sql);
while ($row = mysql_fetch_row($result))
    echo $row[0], "<br />";
?>
but using a PostgreSQL database and, obviously, PostgreSQL functions.

Regards,
Fëanor.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

oops :oops:

you may want to check out this article then :

http://www.devshed.com/Server_Side/PHP/ ... page2.html

also, check out the reference guide available on php.net here :

http://www.php.net/manual/en/ref.pgsql.php
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Hello Fëanor, welcome to PHPDN.
Fëanor wrote:(...) and yes, I've searched the forum and the web.
It seems that your search was not that deep enough, see:

Click here, try the very *first* link returned by Google and you'll get this:
Hope that helps (coding, searching and posting ;)).

Cheers,
Scorphus.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

.. peeking in phppgadmin may help as well :)
Fëanor
Forum Newbie
Posts: 5
Joined: Wed Nov 19, 2003 1:04 am

Post by Fëanor »

Thanks a lot, infolock and scorphus. Next time I'll do my best.

Thanks again,
Fëanor.
Post Reply