Re: getting postgres to emulate mysql/sqlserver bit datatype

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Anton Melser <melser(dot)anton(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: getting postgres to emulate mysql/sqlserver bit datatype
Date: 2007-02-12 00:35:36
Message-ID: 45CFB658.5010205@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Anton Melser wrote:
> Hi,
> I am trying to port an app to postgres and have come up against a most
> annoying problem. The app works with both mysql and sqlserver, who
> both seem to have a bit datatype instead of a proper boolean like pg.
> Alas, pg won't accept 1 and 0 for boolean... and npgsql won't convert
> my numeric(1) into a boolean (and shouldn't either!). Is there any way
> to force pg to accept 1 and 0 for boolean? I know it probably isn't
> optimal, but hey. If there is a standard way to do this (and no,
> rewriting is not an option) I'm all ears.
> Cheers
> Antoine

postgres=# insert into bool_test values(1::boolean);
INSERT 166968558 1
postgres=# insert into bool_test values(0::boolean);
INSERT 166968559 1
postgres=# select * from bool_test ;
one
-----
t
f
(2 rows)

postgres=#

postgres=# insert into bool_test values(cast(0 as boolean));
INSERT 166968560 1
postgres=# insert into bool_test values(cast(1 as boolean));
INSERT 166968561 1
postgres=# select * from bool_test ;
one
-----
t
f
f
t
(4 rows)

>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

--

=== The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive PostgreSQL solutions since 1997
http://www.commandprompt.com/

Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark Walker 2007-02-12 02:02:09 Naming conventions
Previous Message Bill Moseley 2007-02-12 00:20:10 Adjacency List or Nested Sets to model file system hierarchy?