Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AE7C2475BA1 for ; Mon, 4 Nov 2002 11:37:47 -0500 (EST) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by postgresql.org (Postfix) with ESMTP id D19634758DC for ; Mon, 4 Nov 2002 11:37:46 -0500 (EST) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.6/8.12.6) with ESMTP id gA4Ga4KG025108; Mon, 4 Nov 2002 09:36:05 -0700 (MST) Date: Mon, 4 Nov 2002 09:26:05 -0700 (MST) From: "scott.marlowe" To: Jascha Schubert Cc: Subject: Re: Booleans In-Reply-To: <200211041624.22853.JTSMailing@gmx.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailBodyFilter: Message body has not been filtered X-MailScanner: Found to be clean X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/4 X-Sequence-Number: 1586 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.