Subject: | $DBDPG_DEFAULT doesn't seem to work properly |
Date: | Tue, 23 Feb 2016 13:35:07 +0100 |
To: | bug-DBD-Pg [...] rt.cpan.org |
From: | Andreas Guldstrand <andreas.guldstrand [...] gmail.com> |
When using $DBDPG_DEFAULT the first time in a script, it seems to
simply stringify as if I had put it in quotes. Example script:
#!/usr/bin/env perl
use DBI;
my $dbh = DBI->connect('dbi:Pg:dbname=test', '', '');
$dbh->do('create table if not exists test ( id serial primary key,
var varchar not null default \'Test\')');
$dbh->do('insert into test (var) values (?)', {}, $DBD::Pg::DBDPG_DEFAULT);
my $ref = $dbh->selectall_arrayref('select var from test');
print $ref->[0][0], "\n";
-- Expected output:
Test
-- Actual output:
DBD::Pg::DefaultValue=HASH(0x210de88)
If the column was an int, this would have made it error instead:
#!/usr/bin/env perl
use DBI;
my $dbh = DBI->connect('dbi:Pg:dbname=test', '', '');
$dbh->do('create table if not exists test ( id serial primary key,
var int not null default 121)');
$dbh->do('insert into test (var) values (?)', {}, $DBD::Pg::DBDPG_DEFAULT);
my $ref = $dbh->selectall_arrayref('select var from test');
print $ref->[0][0], "\n";
-- Expected output:
121
-- Actual output:
DBD::Pg::db do failed: ERROR: invalid input syntax for integer:
"DBD::Pg::DefaultValue=HASH(0xebfe78)" at ./test.pl line 5.
However, every subsequent use of $DBDPG_DEFAULT in the same script works fine:
#!/usr/bin/env perl
use DBI;
my $dbh = DBI->connect('dbi:Pg:dbname=test', '', '');
$dbh->do('create table if not exists test ( id serial primary key,
var varchar not null default \'Test\')');
$dbh->do('insert into test (var) values (?)', {}, $DBD::Pg::DBDPG_DEFAULT);
$dbh->do('insert into test (var) values (?)', {}, $DBD::Pg::DBDPG_DEFAULT);
my $ref = $dbh->selectall_arrayref('select var from test');
print $ref->[0][0], "\n";
print $ref->[1][0], "\n";
-- Expected output:
Test
Test
-- Actual output:
DBD::Pg::DefaultValue=HASH(0x20abf88)
Test
(Between every run, I execute `dropdb test; createdb test;`)