From: dmp <danap@ttc-cmc.net>
To: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: bit datatype and getObject()
Date: Tue, 23 Nov 2010 20:06:11 -0700
Message-ID: <4CEC8123.4030503@ttc-cmc.net> (raw)
In-Reply-To: <ichd9g$e1g$1@dough.gmane.org>
References: <ichd9g$e1g$1@dough.gmane.org>
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.
Attachments:posgtresql_9.01_datatype_mappings.txt (text/plain, 1.9K) download
------------------------------
PostgreSQL 9.0.1, JDBC 9.0-801
1 data_type_id Data Type Id java.lang.Integer int4 11
2 smallint_type Smallint Type java.lang.Integer int2 6
3 int_type Int Type java.lang.Integer int4 11
4 bigint_type Bigint Type java.lang.Long int8 20
5 decimal_type Decimal Type java.math.BigDecimal numeric 18
6 numeric_type Numeric Type java.math.BigDecimal numeric 12
7 real_type Real Type java.lang.Float float4 14
8 doubleprecision_type Doubleprecision Type java.lang.Double float8 24
9 serial_type Serial Type java.lang.Integer int4 11
10 bigserial_type Bigserial Type java.lang.Long int8 20
11 varchar_type Varchar Type java.lang.String varchar 30
12 char_type Char Type java.lang.String bpchar 30
13 text_type Text Type java.lang.String text 2147483647
14 bytea_type Bytea Type [B bytea 2147483647
15 date_type Date Type java.sql.Date date 13
16 time_type Time Type java.sql.Time time 15
17 timetz_type Timetz Type java.sql.Time timetz 21
18 timestamp_type Timestamp Type java.sql.Timestamp timestamp 29
19 timestamptz_type Timestamptz Type java.sql.Timestamp timestamptz 35
20 interval_type Interval Type org.postgresql.util.PGInterval interval 49
21 boolean_type Boolean Type java.lang.Boolean bool 1
22 point_type Point Type org.postgresql.geometric.PGpoint point 2147483647
23 linesegment_type Linesegment Type org.postgresql.geometric.PGlseg lseg 2147483647
24 box_type Box Type org.postgresql.geometric.PGbox box 2147483647
25 path_type Path Type org.postgresql.geometric.PGpath path 2147483647
26 polygon_type Polygon Type org.postgresql.geometric.PGpolygon polygon 2147483647
27 circle_type Circle Type org.postgresql.geometric.PGcircle circle 2147483647
28 cidr_type Cidr Type java.lang.Object cidr 2147483647
29 inet_type Inet Type java.lang.Object inet 2147483647
30 macaddr_type Macaddr Type java.lang.Object macaddr 2147483647
31 bit2_type Bit2 Type java.lang.Boolean bit 2
32 bitvarying5_type Bitvarying5 Type java.lang.Object varbit 5
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: danap@ttc-cmc.net, spam_eater@gmx.net
Subject: Re: bit datatype and getObject()
In-Reply-To: <4CEC8123.4030503@ttc-cmc.net>
References: <ichd9g$e1g$1@dough.gmane.org> <4CEC8123.4030503@ttc-cmc.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox