Skip site navigation (1) Skip section navigation (2)

Re: BUG #3751: Conversion error using PreparedStatement.setObject()

From: Kris Jurka <books(at)ejurka(dot)com>
To: Lance Andersen <lance(dot)andersen(at)sun(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3751: Conversion error using PreparedStatement.setObject()
Date: 2007-11-15 22:59:00
Message-ID: Pine.BSO.4.64.0711151730350.26847@leary.csoft.net (view raw or flat)
Thread:
Lists: pgsql-bugs

On Thu, 15 Nov 2007, Lance Andersen wrote:

>
> The following bug has been logged online:
>
> Bug reference:      3751
> PostgreSQL version: 8.2.x
> Description:        Conversion error using PreparedStatement.setObject()
> Details:
>
> A PreparedStatement.setObject(1, "1", Types.Bit) will fail with the
> following Exception:

This is not a great test case.

1) It doesn't contain the definition of the Drivers class so it doesn't 
compile.  The whole drivers class and dumping metadata is needless 
complication for a simple test case.

2) It doesn't contain the definition of the bit_tab table, so it doesn't 
run.

3) The error is actually coming from "stmt.executeUpdate(Min_Insert)", not 
a PreparedStatement.

So where does that leave us?

1) The raw insert fails.  INSERT INTO bit_tab (1,0,null) fails because 1 
gets typed as an integer and there are no implicit or assignment casts 
from integer to bit.  You would need to say, '1' so it comes in untyped 
and converted to bit, or be explicit about the type with a cast, saying
1::bit or CAST(1 AS bit).

2) There might be a problem with bit conversion in prepared statements, 
but we didn't get that far.

Other notes:

In PG the bit type is really for multiple bits, not a single 
bit.  Consider SELECT 77::bit(8) results in "01001101".  It's more 
likely that you want to use boolean as the type instead although it 
doesn't have any casts that will help you out in this situation either.

Kris Jurka

In response to

Responses

pgsql-bugs by date

Next:From: Lance J. AndersenDate: 2007-11-15 23:54:18
Subject: Re: BUG #3751: Conversion error using PreparedStatement.setObject()
Previous:From: Lance AndersenDate: 2007-11-15 22:01:33
Subject: BUG #3751: Conversion error using PreparedStatement.setObject()

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group