Thread: DBD::Pg returns 1/0 for boolean field ...

DBD::Pg returns 1/0 for boolean field ...

From
"Marc G. Fournier"
Date:
'k, not sure if I'm overlooking something obvious here, but the query 
below, when run through psql, returns 't' or 'f', as I'd expect:
   SELECT vm.path, vm.company_id, vs.ip_address_id, vm.path AS root_path,          vm.vm_template_id, vt.mount_union
FROM vm_status vs
 
LEFT JOIN virtual_machine vm ON (vs.virtual_machine_id = vm.id)
LEFT JOIN vm_template vt ON (vm.vm_template_id = vt.id)    WHERE vs.stop_date IS NULL      AND vs.server_id IN (SELECT
id                            FROM server                            WHERE server_name = ?
ANDstatus_id = '1' );
 

But, when I run it DBI/DBD::Pg, I'm getting 1's and 0's ...

I'm reading the results as:

$get_hosts->execute($hostname);
$host_array = $get_hosts->fetchall_arrayref({});
foreach my $row (@$host_array) {

and printing the results as:
  print $row->{'mount_union'} . "\n";  next;

Am I doing something wrong, that DBD::Pg is "converting" it to 1's and 
0's?  Or is this expected?


----
Marc G. Fournier           Hub.Org Networking Services (http://www.hub.org)
Email: scrappy@hub.org           Yahoo!: yscrappy              ICQ: 7615664


Re: DBD::Pg returns 1/0 for boolean field ...

From
"Greg Sabino Mullane"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> Am I doing something wrong, that DBD::Pg is "converting" it
> to 1's and 0's?  Or is this expected?

That's expected: in Perl (and many other languages), both raw 't'
and 'f' are considered "true", so DBD::Pg does some mapping. Very
handy when you are passing things back and forth. You can turn this
behavior off with the pg_bool_tf attribute like this:

$dbh->{pg_bool_tf} = 1;

The default is 0. I'm going to move the explanation for this higher
up on the DBD::Pg docs page.
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200511070758
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFDb1AZvJuQZxSWSsgRAj5VAKDSgrNIeTUAlDNEjs1mfQ7ygqkSewCfdkEv
A8jdzpObzN5D8xA4dYIjmZ8=
=l8T8
-----END PGP SIGNATURE-----