Re: setBoolean and char/varchar

From: Barry Lind <barry(at)xythos(dot)com>
To: Paulo Merson <paulo(at)summa-tech(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: setBoolean and char/varchar
Date: 2002-01-17 04:23:44
Message-ID: 3C4651D0.3090809@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Paulo,

No this isn't a bug, but the intended behavior. The client (jdbc in
this case) doesn't know the ultimate datatype of any particular bind
variable. That is only dertermined later when the server parses the SQL
statement. Therefore the client relies on the application to tell it
what the datatype is. Thus when you say setBoolean() you are saying
that the datatype is boolean not varchar. Based on the datatype you say
then the client can build the correct SQL statement. (The client needs
to know whether to send '...set foo = false...' or '...set foo = '0'...'.)

In the get case there is a little more flexibility since the client is
told by the server what the datatype of the value is (and the server
certainly knows this information).

thanks,
--Barry

Paulo Merson wrote:

> If you store '0' and '1' in a varchar(1) or char(1) column, you can read
> false and true respectively using ResultSet.getBoolean. This is great,
> especially if you are migrating from an Oracle database (shamefully
> Oracle doesn't have a Boolean data type).
>
> However, if you try to use PreparedStatement.setBoolean to set a value
> used in the "where" clause to compare to that '0'-or-'1' varchar(1) or
> char(1) column, then your select returns nothing.
>
> Isn't this behavior inconsistent between getBoolean and setBoolean? Is
> this a bug?
>
> (Oracle jdbc driver does allow getBoolean and setBoolean with char(1)
> and varchar2(1) consistently).
>
> Thanks,
>
> Paulo Merson
> Summa Technologies - www.summa-tech.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message David De Mizio 2002-01-17 04:33:58 Datasource question...
Previous Message Vianen, Jeroen van 2002-01-16 19:06:55 Re: Problem with getImportedKeys / getExportedKeys