PerlΒΆ
Connect to CrateDB from Perl applications.
About
DBD::Pg is the PostgreSQL database driver for the Perl DBI module.
Synopsis
example.pl
use DBI;
$dbh = DBI->connect("dbi:Pg:host=localhost;port=5432;sslmode=disable", "crate", "crate")
or die "Cannot connect: $DBI::errstr";
$sth = $dbh->prepare("SELECT region, mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3");
$sth->execute();
$rows = $sth->dump_results();
print($rows);
Start CrateDB using Docker or Podman, then invoke the example program.
docker run --rm --publish=5432:5432 docker.io/crate '-Cdiscovery.type=single-node'
cpan install DBD::Pg
perl example.pl
SSL connection
Use the sslmode=require parameter, and replace username, password,
and hostname with values matching your environment.
Also use this variant to connect to CrateDB Cloud.
$dbh = DBI->connect("dbi:Pg:host=testcluster.cratedb.net;port=5432;sslmode=require", "admin", "password");