#!/opt/perl-5.18/bin/perl use strict; use warnings; use DBI; main(); exit; sub main { my $dbh = DBI->connect('dbi:Pg:',undef,undef,{RaiseError=>1, PrintError=>1, AutoCommit=>0,}) or die "oops - $!\n"; my $sql = " select * from ( values (1, 100, 1000) -- row 1 , (2, 200, 1500) -- row 2 ) as f(id, debet, credit) order by id; "; my $sth = $dbh->prepare( $sql ) or die "oops - prepare - $!\n"; my $rc = $sth->execute() or die "oops - execute - $!\n"; my %row; $sth->bind_columns( \( @row{ @{ $sth->{ NAME_lc} } } ) ); while ($sth->fetch) { print " id ", $row{ id } , "\n"; print " credit ", $row{ credit } , "\n"; print " debet ", $row{ debet } , "\n\n"; } $dbh->disconnect; } # note that fetch is an alias for fetchrow_arrayref #### $ perl arrayref.pl id 1 credit 1000 debet 100 id 2 credit 1500 debet 200