Re: Perl won't eval PgSQL boolean value

From: "Peter Haworth" <pmh(at)edison(dot)ioppublishing(dot)com>
To: Randall Perry <rgp(at)systame(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Perl won't eval PgSQL boolean value
Date: 2001-09-05 10:29:06
Message-ID: PGM.20010905102906.16468.986@edison.ioppublishing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 02 Sep 2001 20:01:27 -0400, Randall Perry wrote:
> I've got an if statement that checks if a boolean value is true:
>
> if ($cust_data->{'hold'} eq 't')
>
> But perl will not evaluate the value. $cust_data->{'hold'} is taken from a
> PgSQL boolean field (either t or f). If I use the construct above it tell
> me that 'eq' is not defined thinking it's a string.

Assuming that you're using DBI and DBD::Pg, the problem is that DBD::Pg
returns 1 and 0 for booleans, rather than the expected 't' and 'f'. This
means that if you know you're always going to use Postgres (and that DBD::Pg
isn't going to change), you can simply say:

if($cust_data->{hold})

However, if you want cross-database portability (and protection from
DBD::Pg's behaviour changing), you have to do this:

if($cust_data->{hold}=~/[t1]/)

--
Peter Haworth pmh(at)edison(dot)ioppublishing(dot)com
perl -e '$|=s""\rJust another Perl hacker,";s/\w/$&\b#/g;
s/(${\chr(97+rand$=)}).#/$1/ig&&sleep print while/#/;die$/'
-- Ilmari Karonen, Yanick and Abigail

In response to

Browse pgsql-general by date

  From Date Subject
Next Message P.J. "Josh" Rovero 2001-09-05 12:27:32 Glacial deletes (fixed), now glacial lo vacuum
Previous Message Martijn van Oosterhout 2001-09-05 10:06:17 Re: many junction tables