Re: describe table (from perl)

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: describe table (from perl)
Date: 2005-05-16 23:00:02
Message-ID: 511e2b0ebbd2fd6f1cfb637ec3a8934d@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


-----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(at)turnstep(dot)com
PGP Key: 0x14964AC8 200505161856
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message postgresql.org 2005-05-17 04:15:15 Re: problems with postgresql.msi (installing 8.0.2)
Previous Message Sean Davis 2005-05-16 21:23:34 Re: Writing First Trigger Function in PostgreSQL