Re: Using boolean '1' in jdbc2

From: "Glenn R(dot) Kronschnabl" <grk(at)netquotient(dot)com>
To: Rene Pijlman <rene(at)lab(dot)applinet(dot)nl>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Using boolean '1' in jdbc2
Date: 2001-09-14 03:58:23
Message-ID: 1000439904.3600.15.camel@acoldone3
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I'm that person. I'm not trying to do anything convoluted. ;-)

I have a schema & data from Oracle that uses a 'fake' boolean column.
(Stupid oracle doesn't support type boolean afaik - uses number). I
find the easiest way to adapt the schema & data to postgresql is to
*not* convert the 'fake' boolean fields (enforced in Oracle using
constraints) to postgresql boolean but to use either numeric(1) or
integer. Why? Because all my data (already exported) has 0's and 1's
and it would be a waste to try convert all the data to true/false, which
postgresql requires for a boolean field. If there is a trick which
allows 0's and 1's to be imported into a boolean field, I guess I could
use that instead!?

So - the submitted patch allows a boolean field to be implemented using
either numeric or integer fields - I think this is pretty common. An
according to the archives, this has been dicussed before.

Glenn

On Thu, 2001-09-13 at 14:46, Rene Pijlman wrote:
> On Thu, 13 Sep 2001 15:29:38 -0400 (EDT), you wrote:
> >> Bruce Momjian writes:
> >> > I noticed that jdbc1 getBoolean allows '1', while jdbc2 does not. The
> >> > following patch makes jdbc2 accept '1' also. Is this OK?
> >>
> >> Why? Booleans always come out as 't' or 'f'.
> >
> >Someone emailed me privately that they wanted to use '1' for
> >boolean. No idea why, and no idea why jdbc1 has it.
>
> In jdbc1 the string to boolean conversion is implemented within
> getBoolean() itself, which interprets data from the PostgreSQL
> backend.
>
> In jdbc2 its implemented in a helper method
> ResultSet.toBoolean(), which is public, probably because its now
> also used in the new Array feature.
>
> Perhaps someone is now using ResultSet.toBoolean() as a utility
> method. I don't think that's a good idea. Even though its public
> its not part of any published interface. So anyone who wants to
> convert 1 to true should use his own method. We could rule this
> out by declaring the method protected or package (no access
> specifier).
>
> This doesn't explain why jdbc1 accepts '1' though. Anyone?
>
> Regards,
> René Pijlman <rene(at)lab(dot)applinet(dot)nl>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Alexaki Sofia 2001-09-14 06:49:09 Re: Transaction size limit & Data Truncation
Previous Message Barry Lind 2001-09-14 01:50:02 Re: Using boolean '1' in jdbc2