tableDesc (sample/psql.rb)

    # File sample/psql.rb, line 240
    def tableDesc(ps, table)
      descbuf  = "SELECT a.attnum, a.attname, t.typname, a.attlen"
      descbuf += "  FROM pg_class c, pg_attribute a, pg_type t "
      descbuf += "    WHERE c.relname = '"
      descbuf += table
      descbuf += "'"
      descbuf += "    and a.attnum > 0 "
      descbuf += "    and a.attrelid = c.oid "
      descbuf += "    and a.atttypid = t.oid "
      descbuf += "  ORDER BY attnum "

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

      # first, print out the attribute names
      nColumns = res.num_tuples()
      if nColumns > 0
        #
        # Display the information
        #

        printf("\nTable    = %s\n", table)
        printf("+----------------------------------+----------------------------------+-------+\n")
        printf("|              Field               |              Type                | Length|\n")
        printf("+----------------------------------+----------------------------------+-------+\n")

        # next, print out the instances
        for i in 0..res.num_tuples-1

          printf("| %-32.32s | ", res.getvalue(i, 1))
          rtype = res.getvalue(i, 2);
          rsize = res.getvalue(i, 3).to_i

          if (rtype.eql?("text"))
            printf("%-32.32s |", rtype)
            printf("%6s |", "var")
          elsif (rtype.eql?("bpchar"))
            printf("%-32.32s |", "(bp)char")
            printf("%6i |", if (rsize > 0) then rsize - 4 else 0 end)
          elsif  (rtype.eql?("varchar"))
            printf("%-32.32s |", rtype)
            printf("%6d |", if (rsize > 0) then rsize - 4 else 0 end)
          else
            # array types start with an underscore
            if (rtype[0, 1] != '_')
              printf("%-32.32s |", rtype)
            else
              newname = rtype + "[]"
              printf("%-32.32s |", newname)
            end
            if (rsize > 0)
              printf("%6d |", rsize)
            else
              printf("%6s |", "var")
            end
          end
          printf("\n")
        end
        printf("+----------------------------------+----------------------------------+-------+\n")

        res.clear()

      else
        printf(STDERR, "Couldn't find table %s!\n", table)
      end
    end