$sqltable = "SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname ~ '^(sum_partn_avail)\$' AND n.nspname ~ '^(public)\$' ORDER BY c.oid"; $sth = $dbh->prepare($sqltable); if ( !defined $sth ) { die "Cannot prepare statement: $DBI::errstr\n"; } # Execute the statement at the database level $sth->execute; $found = 0; while(@sresult = $sth->fetchrow()) { #get each row from the DB if(!$found++) { #print "

The query result is:

"; } $id = pop(@sresult); } $sqltable = "SELECT a.attname as COLUMN FROM pg_catalog.pg_attribute a WHERE a.attrelid = '$id' AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum"; $sth = $dbh->prepare($sqltable); if ( !defined $sth ) { die "Cannot prepare statement: $DBI::errstr\n"; } # Execute the statement at the database level $sth->execute; $found = 0; while(@sresult = $sth->fetchrow()) { #get each row from the DB if(!$found++) { #print "

The query result is:

"; } print "@sresult

"; }