Re: Using boolean '1' in jdbc2 - Mailing list pgsql-jdbc

From Glenn R. Kronschnabl
Subject Re: Using boolean '1' in jdbc2
Date
Msg-id 1000439904.3600.15.camel@acoldone3
Whole thread Raw
In response to Re: Using boolean '1' in jdbc2  (Rene Pijlman <rene@lab.applinet.nl>)
Responses Re: Using boolean '1' in jdbc2
Re: Using boolean '1' in jdbc2
List 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@lab.applinet.nl>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org



pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: Using boolean '1' in jdbc2
Next
From: Barry Lind
Date:
Subject: Re: Using boolean '1' in jdbc2