[techtalk] Postgresql and perl...

Nils Philippsen nils at wombat.dialup.fht-esslingen.de
Tue Jan 4 19:52:52 EST 2000


On Tue, 4 Jan 2000, Michelle Leonard wrote:

> So now my question is where are examples/docs on how
> to hook into this using perl instead of pgsql?  I did
> install the postgresql-perl rpm...

You use the module Pg:

-- 8< -- snip --
use Pg;

my $conn;
my @resultarray;
my $row;
my $col;

$conn = PG::connectdb("host=mydbserver dbname=mydatabase");

Pg::doQuery ($conn, "SELECT foo FROM bar WHERE baz=0", \@resultarray);

for $row (0..$#resultarray) {
  for $col (0..$#{$resultarray[$row]}) {
    print $resultarray[$row][$col] . "\t";
  }
  print "\n";
}
-- 8< -- snap

or:

[...]
my $result = PQexec ($conn, "....");
[...]
print $result->getvalue ($row, $col);
[...]

for more info, see 'man Pg' or 'perldoc Pg'.

Nils
-- 
 Nils Philippsen / Berliner Straße 39 / D-71229 Leonberg // +49.7152.209647
nils at wombat.dialup.fht-esslingen.de / nils at fht-esslingen.de / nils at redhat.de
   The use of COBOL cripples the mind; its teaching should, therefore, be
   regarded as a criminal offence.                  -- Edsger W. Dijkstra


************
techtalk at linuxchix.org   http://www.linuxchix.org




More information about the Techtalk mailing list