#!/usr/local/bin/perl -w use strict; use DBI; use DBD::Pg; my ($dbh, @tables); my $user = "username"; my $password = ""; my $db_name="database"; my $driver="Pg"; my $db_host="localhost"; my $dsn="DBI:$driver:dbname=$db_name;host=$db_host"; $dbh=DBI->connect($dsn,$user,$password) or die "Can't connect: $DBI::errstr"; @tables = $dbh->tables; for my $thisTable (@tables) { my $sth=$dbh->prepare("select * from $thisTable where 1 = 0"); $sth->execute(); my $columnRef=$sth->{NAME_lc}; for my $thisColumn (@$columnRef) { print "Table: $thisTable, column is: $thisColumn\n"; # Do whatever else you want with the columns. } 1; } $dbh->disconnect(); #### @tables = grep { s/.*\.//o } @tables;