Thread: describe table (from perl)

describe table (from perl)

From
"Celia McInnis"
Date:
What's the easiest way to have perl (using the DBI module) extract table
information? I need to be able to extract column names and types. (Something
like what is given by the MySql "DESCRIBE mytable" command).

Thanks,
Celia McInnis


Re: describe table (from perl)

From
"Greg Sabino Mullane"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> What's the easiest way to have perl (using the DBI module) extract table
> information? I need to be able to extract column names and types. (Something
> like what is given by the MySql "DESCRIBE mytable" command).

You want the column_info() method: it's documented in DBI and in DBD::Pg.
Usage is something like this:

$table = "foobar";
$sth = $dbh->column_info('','',$table,'');
$info = $sth->fetchall_arrayref({});
print Dumper $info;

In particular, you want the COLUMN_NAME and TYPE_NAME attributes. Also look
at the "pg_type" attribute, which gives a friendlier version of TYPE_NAME.

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200505161856
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFCiSWwvJuQZxSWSsgRAsQCAJ9ovbiDS9Wej34z0BbfKwg81lQCgQCgs+cF
HCnypGWqGWE1YAU1y37zsZg=
=Mje/
-----END PGP SIGNATURE-----