in reply to Postgresql output to file

Looking at the DBI documentation, I don't think your usage of $dbh->($query) is supported. What error message do you get?

If you are mainly looking at producing a report from an SQL query, Querylet has good and simplistic support for creating CSV files.

If this is only a stepping stone to do more with the data than just print it, but you want to inspect the data visually, there is DBIx::RunSQL->format_results , which returns a query result formatted as an ASCII table.

The example usage shows the following code, which could also be a suitable guideline for you for how to run a query using DBI:

my $sth= $dbh->prepare( 'select * from foo' ); $sth->execute(); print DBIx::RunSQL->format_results( sth => $sth );