Re: How to implement Microsoft Access boolean (YESNO)

From: PFC <lists(at)peufeu(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to implement Microsoft Access boolean (YESNO)
Date: 2006-01-24 10:14:58
Message-ID: op.s3vn28xdcigqcu@apollo13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, 24 Jan 2006 06:03:48 +0100, Greg Stark <gsstark(at)mit(dot)edu> wrote:

> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>
>> Greg Stark <gsstark(at)mit(dot)edu> writes:
>> > "Jesper K. Pedersen" <jkp(at)solnet(dot)homeip(dot)net> 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")],)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2006-01-24 14:59:01 Re: How to implement Microsoft Access boolean (YESNO)
Previous Message Bruno Wolff III 2006-01-24 09:04:39 Re: non-equi self-join optimization