Page 1 of 1

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

Posted: Wed Nov 19, 2003 1:04 am
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.

Posted: Wed Nov 19, 2003 1:16 am
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)

Posted: Wed Nov 19, 2003 1:48 am
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.

Posted: Wed Nov 19, 2003 2:03 am
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

Posted: Wed Nov 19, 2003 9:32 pm
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.

Posted: Thu Nov 20, 2003 8:53 am
by Stoker
.. peeking in phppgadmin may help as well :)

Posted: Thu Nov 20, 2003 3:30 pm
by Fëanor
Thanks a lot, infolock and scorphus. Next time I'll do my best.

Thanks again,
Fëanor.