Re: Perl won't eval PgSQL boolean value - Mailing list pgsql-general

From Peter Haworth
Subject Re: Perl won't eval PgSQL boolean value
Date
Msg-id PGM.20010905102906.16468.986@edison.ioppublishing.com
Whole thread Raw
In response to Perl won't eval PgSQL boolean value  (Randall Perry <rgp@systame.com>)
List 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@edison.ioppublishing.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

pgsql-general by date:

Previous
From: Gabriel Fernandez
Date:
Subject: FOREIGN KEY: MATCH FULL
Next
From: Martijn van Oosterhout
Date:
Subject: Re: many junction tables