Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id EDD6C632FDB; Wed, 10 Feb 2010 17:56:57 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 49099-01; Wed, 10 Feb 2010 21:56:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f179.google.com (mail-pz0-f179.google.com [209.85.222.179]) by mail.postgresql.org (Postfix) with ESMTP id C96D9632693; Wed, 10 Feb 2010 17:56:46 -0400 (AST) Received: by pzk9 with SMTP id 9so527655pzk.28 for ; Wed, 10 Feb 2010 13:56:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=cox6e8jp3Q4ykvTa3cGkZfqQJwR9XztB0EHV3oalcPY=; b=UVkSdSVm7IXcTIwaSQ9+Gerv/OhYbwwdXuEIGDCVsB5gkspkKZvHr3Bki06u2Axttw JsOr+OlVVYmgDwHwCDVJ6i46Jf57MrTcqOKW5Ln5UoG2Ke4oqxk74joa73FE6QFg8ETt WAX9Eu+k+nJcPVfMMZEiy57rAdHbtVdEZoPks= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=ZcwW9XqVA6YIq0rKpKiYUDHCARd0zkHeSNuG3NDYvqOKLtMPJRXOfNWodZjtZ7rPcA nuVugRp4rbQ3mdnSFgXSg6/vHig5QN/7fWIn5UZA9/4yOH9M0ZM+K03XPS7jaNmH3UDy I7EFiRGp/rhNsdP0rnx3/ZK2iyC8GUPXTDn50= Received: by 10.142.121.10 with SMTP id t10mr534605wfc.152.1265839005221; Wed, 10 Feb 2010 13:56:45 -0800 (PST) Received: from ?192.168.2.65? (office.squiz.net [203.206.128.174]) by mx.google.com with ESMTPS id 23sm1926484pzk.4.2010.02.10.13.56.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Feb 2010 13:56:43 -0800 (PST) Message-ID: <4B732B94.20007@gmail.com> Date: Thu, 11 Feb 2010 08:56:36 +1100 From: Chris User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Thom Brown CC: pgsql-php@postgresql.org, PGSQL Mailing List Subject: Re: [PHP] PHP and PostgreSQL boolean data type References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.895 tagged_above=-10 required=5 tests=AWL=0.704, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/459 X-Sequence-Number: 159235 Thom Brown wrote: > Hi, > > A long-standing problem we've had with PostgreSQL queries in PHP is > that the returned data for boolean columns is the string 'f' instead > of the native boolean value of false. > > An obvious example of this would be for a table with users and their > boolean registered status: > > Select user, registered From users; > > Then getting a row from the result would reveal: array('user' => > 'thomb', registered => 'f'); That's how postgres stores them, php doesn't understand the field is a boolean. # create table a(a int, b boolean); # insert into a(a, b) values (1, true); # insert into a(a, b) values (2, false); # SELECT * from a; a | b ---+--- 1 | t 2 | f (2 rows) Also while not in the "official" docs, it is a note from 2002: http://www.php.net/manual/en/ref.pgsql.php#18749 and http://www.php.net/manual/en/function.pg-fetch-array.php says Each value in the array is represented as a string. Database NULL values are returned as NULL. > Another problem is with arrays, where they are difficult to parse as > they also come through as plain strings with no binary alternative. Haven't played with postgres arrays so can't say either way - but same as above, php just fetches the data. There's an example that might help you - http://www.php.net/manual/en/ref.pgsql.php#89841 -- Postgresql & php tutorials http://www.designmagick.com/