[development] Postgres equivalent to SHOW TABLES

Nancy Wichmann nan_wich at bellsouth.net
Fri Sep 4 23:19:53 UTC 2009


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.


Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King,
Jr.



More information about the development mailing list