X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 739239DCAC9 for ; Tue, 24 Jan 2006 06:14:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28131-04 for ; Tue, 24 Jan 2006 06:14:45 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from peufeu.com (boutiquenumerique.com [82.67.9.10]) by postgresql.org (Postfix) with ESMTP id D22C79DCA58 for ; Tue, 24 Jan 2006 06:14:40 -0400 (AST) Received: (qmail 4223 invoked from network); 24 Jan 2006 11:14:59 +0100 Received: from boutiquenumerique.com (HELO apollo13) (82.67.9.10) by boutiquenumerique.com with SMTP; 24 Jan 2006 11:14:59 +0100 To: pgsql-sql@postgresql.org Subject: Re: How to implement Microsoft Access boolean (YESNO) References: <20060122211351.371f20d8@io.solnet> <22008.1137962771@sss.pgh.pa.us> <20060122221328.433038a9@io.solnet> <873bjewts8.fsf@stark.xeocode.com> <8505.1138050132@sss.pgh.pa.us> <87r76yusi3.fsf@stark.xeocode.com> Message-ID: Date: Tue, 24 Jan 2006 11:14:58 +0100 From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: <87r76yusi3.fsf@stark.xeocode.com> User-Agent: Opera M2/8.51 (Linux, build 1462) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.04 required=5 tests=[AWL=0.040] X-Spam-Score: 0.04 X-Spam-Level: X-Archive-Number: 200601/152 X-Sequence-Number: 23941 On Tue, 24 Jan 2006 06:03:48 +0100, Greg Stark wrote: > Tom Lane writes: > >> Greg Stark writes: >> > "Jesper K. Pedersen" writes: >> >> Having checked the I/O format it seems that MS Access exports the >> >> values of a YESNO field as 0 and 1 >> >> > If only Postgres's boolean type were as helpful. >> >> There's a cast to int in 8.1, and you can roll-your-own easily in prior >> releases ... > > The annoying thing about is that in just about any client language > you'll get > 't' and 'f' by default and both will evaluate to false. So any user who > tries > to do things the obvious way like this will get a surprise: I guess this depends on the smartness of the language's client library. psycopg2 on python happily converts pg's types to and from python's native types (bool, int, datetime, arrays of these, etc...). All types are supported except GIST stuff like polygons (but you can write a type converter for these). Never ever quote an argument again ! Life is good. >>> DB.execute("SELECT (1=1)::bool, (1=0)::bool"); DB.fetchone() (True, False) >>> DB.execute("SELECT '{1,2,3,4}'::INTEGER[]"); DB.fetchone() ([1, 2, 3, 4],) >>> DB.execute("SELECT '{1,2,3,4}'::NUMERIC[]"); DB.fetchone() ([Decimal("1"), Decimal("2"), Decimal("3"), Decimal("4")],)