[development] Postgres equivalent to SHOW TABLES

Khalid Baheyeldin kb at 2bits.com
Sat Sep 5 00:51:38 UTC 2009


On Fri, Sep 4, 2009 at 7:19 PM, Nancy Wichmann <nan_wich at bellsouth.net>wrote:

> Ivan Sergio Borgonovo wrote:
> > A better way would be to learn how to query information_schema that
> > *should* be portable.
>
> Well, I don't know about portable, but the MySql manual is wrong in its
> comparison.
>  $list = array();
>  $result = db_query("SHOW TABLES LIKE 'abc\_%'");
>  while ($table = db_result($result)) {
>    $list[] = $table;
>  }
>
> Worked just fine. However, to make it work with information_schema
> required:
>  $list = array();
>  $result = db_query("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE
> table_name LIKE 'abc\_%'");
>  while ($table = db_fetch_array($result)) {
>    $list[] = $table['table_name'];
>  }
>  $list = array_unique($list);
>  sort($list);
>
> Note that the list had MANY duplicates in it and did not come out in order
> of table name.
>
>
This is plain SQL, and hence there is nothing stopping you from using
DISTINCT as well as ORDER BY, like any other SQL. It should be portable
between MySQL and PostgreSQL.
-- 
Khalid M. Baheyeldin
2bits.com, Inc.
http://2bits.com
Drupal optimization, development, customization and consulting.
Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
Simplicity is the ultimate sophistication. --   Leonardo da Vinci
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.drupal.org/pipermail/development/attachments/20090904/b44f2b9d/attachment-0001.htm>


More information about the development mailing list