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

From postgres@vsservices.com
Subject Re: Perl won't eval PgSQL boolean value
Date
Msg-id 01090314272700.99384@prime.vsservices.com
Whole thread Raw
In response to Perl won't eval PgSQL boolean value  (Randall Perry <rgp@systame.com>)
List pgsql-general
On Sunday 02 September 2001 19:01, 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.

This should work just fine.  It sounds like a quote is being dropped
somewhere...
I just tested it here and it works just fine.

> If I use:
> if ($cust_data->{'hold'} == 't')
>
> I get an error saying $cust_data->{'hold'} is a non-numeric value.
Which is what it should do.  '==' is for numerics only.

> If I do this:
>  if ($cust_data->{'hold'})
>
> it will always evaluate to true whether the value is 't' or 'f'.
Again, what it should do,  both 't' and 'f' are non-zero as far as Perl is
concerned.

>
> HELP. How do you evaluate boolean values from PgSQL in Perl?

Your first choice (value eq 't') should do the trick.  However, it sounds
like there is another problem interfering with it.  Could we see the code?

GB

--
GB Clark II             | Roaming FreeBSD Admin
gclarkii@VSServices.COM | General Geek
           CTHULU for President - Why choose the lesser of two evils?

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Question about plan
Next
From: Francesco Casadei
Date:
Subject: Catching errors inside a function