Skip Menu |

This queue is for tickets about the DBD-Pg CPAN distribution.

Report information
The Basics
Id: 12978
Status: resolved
Priority: 0/
Queue: DBD-Pg

People
Owner: Nobody in particular
Requestors: peter [...] pajamian.dhs.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: unknown data types do not default to SQL_VARCHAR in DBD::Pg 1.42
Distribution name and version: DBD-Pg-1.42 Perl version: This is perl, v5.8.6 built for i686-linux Operating System vendor and version: Linux 2.6.9-5.0.5.106.unsupportedsmp #1 SMP Tue May 10 01:19:44 CDT 2005 i686 athlon i386 GNU/Linux Here's a simplified test case: #!/usr/bin/perl -w use strict; use DBI; my $dbh = DBI->connect("dbi:Pg:dbname=template1", 'postgres', ''); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; my $sth = $dbh->prepare('SELECT ? AS test'); $sth->execute('It works'); my $arrayref = $sth->fetchrow_arrayref; undef $sth; print $arrayref->[0] . "\n"; $dbh->commit; $dbh->disconnect; Running the above program gives the following result: DBD::Pg::st execute failed: ERROR: could not determine data type of parameter $1 DBD::Pg::st execute failed: ERROR: could not determine data type of parameter $1 Issuing rollback() for database handle being DESTROY'd without explicit disconnect(). However, if I change the program to the following: #!/usr/local/bin/perl -w use strict; use DBI qw(:sql_types); my $dbh = DBI->connect("dbi:Pg:dbname=template1", 'postgres', ''); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; my $sth = $dbh->prepare('SELECT ? AS test'); $sth->bind_param(1,undef,SQL_VARCHAR); $sth->execute('It works'); my $arrayref = $sth->fetchrow_arrayref; undef $sth; print $arrayref->[0] . "\n"; $dbh->commit; $dbh->disconnect; ...then it works fine with the following output: It works
This is a "limitation" of the backend parser - it cannot determine the data type in the context that you gave it. Since we pass it off to the parser and let it tell us the types, this is all correct behavior. You can bind the param yourself as in the example above, or you could write something like this: SELECT ?::varchar. You could also set $dbh->{pg_server_prepare} = 0 to not allow the backend to parse the query by avoiding server-side prepared statements.