# File sample/psql.rb, line 171
def tableList(ps, deep_tablelist, info_type, system_tables)
  listbuf  = "SELECT usename, relname, relkind, relhasrules"
  listbuf += "  FROM pg_class, pg_user "
  listbuf += "WHERE usesysid = relowner "
  case info_type
  when 't'
    listbuf += "and ( relkind = 'r') "
  when 'i'
    listbuf += "and ( relkind = 'i') "
    haveIndexes = true
  when 'S'
    listbuf += "and ( relkind = 'S') "
  else
    listbuf += "and ( relkind = 'r' OR relkind = 'i' OR relkind='S') "
    haveIndexes = true
  end
  if (!system_tables)
    listbuf += "and relname !~ '^pg_' "
  else
    listbuf += "and relname ~ '^pg_' "  
  end
  if (haveIndexes)
    listbuf += "and (relkind != 'i' OR relname !~'^xinx')"
  end
  listbuf += "  ORDER BY relname "

  res = PSQLexec(ps, listbuf)
  if res == nil
    return
  end

  # first, print out the attribute names
  nColumns = res.num_tuples
  if nColumns > 0
    if deep_tablelist
      table = res.result
      res.clear
      for i in 0..nColumns-1
        tableDesc(ps, table[i][1])
      end
    else
      # Display the information

      printf("\nDatabase    = %s\n", ps.db.db)
      printf(" +------------------+----------------------------------+----------+\n")
      printf(" |  Owner           |             Relation             |   Type   |\n")
      printf(" +------------------+----------------------------------+----------+\n")

      # next, print out the instances
      for i in 0..res.num_tuples-1
        printf(" | %-16.16s", res.getvalue(i, 0))
        printf(" | %-32.32s | ", res.getvalue(i, 1))
        rk = res.getvalue(i, 2)
        rr = res.getvalue(i, 3)
        if (rk.eql?("r"))
          printf("%-8.8s |", if (rr[0] == 't') then "view?" else "table" end)
        else
          printf("%-8.8s |", "index")
        end
        printf("\n")
      end
      printf(" +------------------+----------------------------------+----------+\n")
      res.clear()
    end
  else
    printf(STDERR, "Couldn't find any tables!\n")
  end
end