Hi,
this is what I used some time ago. Don't know if it works now :-)
Regards,
Oleg
#!/usr/bin/perl
# Print information about database
use Pg;
$dbmain='mdb';
$conn = Pg::connectdb("dbname = $dbmain");
foreach ( keys (%conn) ) {
print "$conn{$_}\n";
}
$pghost=$conn->host;
$pgport=$conn->port;
print "host=$pghost \n";
print "port=$pgport \n";
# get information about all tables in $dbmain
$query_db_info='SELECT usename, relname, relkind, relhasrules FROM pg_class, pg_user
WHERE ( relkind = \'r\' OR relkind = \'i\') and relname !~ \'^pg_\' and relname !~
\'^Inv[0-9]+\' and usesysid = relowner ORDER BY relname';
$query=$conn->exec($query_db_info);
$ntups=$query->ntuples;
print "Database <$dbmain> has $ntups tables\n";
$nfields=$query->nfields;
print "$nfields\n";
foreach ( $tup_num=0; $tup_num < $ntups; ++$tup_num ) {
#$tup_num=0;
foreach ($i=0; $i<$nfields; ++$i) {
$fname=$query->fname($i);
$fnumber=$query->fnumber($fname);
$ftype=$query->ftype($i);
$fsize=$query->fsize($i);
# print "$i:$fname:$fnumber:$ftype:$fsize\n";
$value=$query->getvalue($tup_num, $i);
print "$tup_num:$fname=$value\n";
}
}
On Thu, 27 May 1999, áÎÄÒÅÊ îÏ×ÉËÏ× wrote:
> Date: Thu, 27 May 1999 15:46:48 +0400
> From: áÎÄÒÅÊ îÏ×ÉËÏ× <[EMAIL PROTECTED]>
> To: pgsql-admin <[EMAIL PROTECTED]>
> Subject: [ADMIN] Getting table structure from script
>
> Hello.
>
> Is there any way to get table structure from perl script
> (for instance using Pg). I need it very much, but now have
> to use copy/paste algorythm :)
>
> Andrey Novikov
>
>
>
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: [EMAIL PROTECTED], http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83