Re: Booleans

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Jascha Schubert <JTSMailing(at)gmx(dot)net>
Cc: <pgsql-php(at)postgresql(dot)org>
Subject: Re: Booleans
Date: 2002-11-04 16:26:05
Message-ID: Pine.LNX.4.33.0211040922510.21951-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

On Mon, 4 Nov 2002, Jascha Schubert wrote:

> Hi,
> I've written an php script with many queries like
>
> "insert into table (a,b,c) VALUES('$q','$w','$e')"
>
> where $q,$w and $e are booleans. I've written it with mysql and it works fine
> there, now I want to use it with postgres and have the following problem:
> As type for a,b and c I used the bit type with length 1. Now if $q is true
> there is now problem it evaluates to '1', but false evaluates to '' and
> postgres then complains that the bit string length does not match. Its
> clearly why it happens, but is there an easy way to fix this, without
> rewriting all the sql queries with something like if($q===false) $q='0';.

I'd recommend taking off your mysql thinking cap for this one. :-)

To set your values, I'd suggest using the TRUE and FALSE method, like so:

insert into table (a,b,c) values (TRUE,FALSE,FALSE)

So that you use PHP to set each field to TRUE or FALSE (note there's no '
marks around the TRUE or FALSE).

When testing for true or false, do it the same basic way:

select * from table where a IS TRUE

or

select * from table where a IS TRUE and (b IS FALSE or c IS FALSE)

kind of thing.

That keeps you from having to worry about how TRUE and FALSE are being
stored in the database.

In response to

  • Booleans at 2002-11-04 15:24:22 from Jascha Schubert

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Keary Suska 2002-11-04 17:27:10 Re: Booleans
Previous Message Jascha Schubert 2002-11-04 15:24:22 Booleans