The DBI defines methods for getting metadata. If you want to get info on a given table, though, you have to go through a statement handle. It's a little bit involved after that. You execute a "select * from table_name" (or, if you know the field names you're interested in, just get those) and then the driver makes other info available to you via the {NAME} and {TYPE} attributes of the statement handle.

The *statement handle* attribute {NAME} is a reference to an array of the names of the fields returned by the current statement, and there's also the Probably the most straightforward way of doing this looks something like this:
# you've already got your DB handle: my @tables = $db->tables(); foreach my $table (@tables) { my $sql = "select * from $table"; my $sth = $db->prepare( $sql ); $sth->execute(); # check for errors, either set RaiseError or have + a "die" clause here print "Structure of $table \n\n"; my $num_fields = $sth->{NUM_OF_FIELDS}; for ( my $i=0; $i< $num_fields; $i++ ) { my $field = $sth->{NAME}->[$i]; my $type = $sth->{TYPE}->[$i]; my $precision = $sth->{PRECISION}->[$i]; # e.g. VARCHAR(50) ha +s a precision of 50 print "Field $field is of type $type, with precision $ precisi +on\n"; } $sth->finish(); }

You can turn those numeric types into more descriptive names, I don't know anything specifically about DBI::Pg, and my knowledge is derived from the very useful Programming the Perl DBI, which has been surpassed on the metadata issue via newer versions of the DBI, but I see that those newer versions of the DBI define type_info methods that can help you figure out which types you're dealing with.

HTH.

I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity -- F. Nietzsche


In reply to Re: Getting column size/type From DBI by arturo
in thread Getting column size/type From DBI by BigGuy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.