From: | dmp <danap(at)ttc-cmc(dot)net> |
---|---|
To: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: bit datatype and getObject() |
Date: | 2010-11-24 03:06:11 |
Message-ID: | 4CEC8123.4030503@ttc-cmc.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Thomas Kellerer wrote:
> Hi,
>
> the JDBC driver seems to map columns defined as "bit" to Boolean
> regardless of the definition of the column. So even a bit(5) is returned
> as boolean value which I think is not correct.
>
> Consider the following
>
> CREATE TABLE bit_test (some_bits bit(5));
> INSERT INTO bit_test VALUES ('01010');
>
> When I run a select in psql it will return 01010 as the column's value.
>
> When running a select from within Java and using getObject() on that
> column a java.lang.Boolean is returned.
>
> This might be correct for a bit(1) but not for columns defined with a
> bigger width.
>
> It is returned correctly when using getString() on that column though.
> But for applications using the generic getObject() this returns a wrong
> value.
>
> I'm not sure what the JDBC specs requires here, but this mapping somehow
> is confusing.
>
> I tested this with PG 9.0 and the JDBC4 build 801 driver.
>
> Regards
> Thomas
It is true that the mapping is java.lang.Boolean for the bit(x), but
there is another type in PostgreSQL to define a multi-bit type. Have
you tried: bit varying(5) retrieval by getObject()? Because that type
does map to java.lang.Object. The PostgreSQL manual 8.10 though indicates
that both are: "Bit String Types". Seems appropriate that getString()
then is how to retrieve these types. Either way isn't this a server
issue on the mapping, not the JDBC? I'm not sure but does not the JDBC
just return the mapping from the server?
Attached current data types mapping for majority of data types of server
9.0.1 and JDBC 9.0-801.
danap.
Attachment | Content-Type | Size |
---|---|---|
posgtresql_9.01_datatype_mappings.txt | text/plain | 1.9 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Kris Jurka | 2010-11-24 06:31:13 | Re: bit datatype and getObject() |
Previous Message | Thomas Kellerer | 2010-11-23 21:55:57 | bit datatype and getObject() |