BUG #1192: JDBC driver: org.postgresql.jdbc2.Array throws Bad BigDecimal Exception - Mailing list pgsql-bugs

From PostgreSQL Bugs List
Subject BUG #1192: JDBC driver: org.postgresql.jdbc2.Array throws Bad BigDecimal Exception
Date
Msg-id 20040714071255.90742CF49E3@www.postgresql.com
Whole thread Raw
Responses Re: BUG #1192: JDBC driver: org.postgresql.jdbc2.Array throws
List pgsql-bugs
The following bug has been logged online:

Bug reference:      1192
Logged by:          oliver dauben (adc hofheim)

Email address:      oliver@arachnerd.de

PostgreSQL version: 7.4

Operating system:   any (tested w/ win NT, win XP, linux 2.4.x)

Description:        JDBC driver: org.postgresql.jdbc2.Array throws Bad
BigDecimal Exception

Details:

i'm working with NUMERIC(32,16) arrays in a DB table.

psql retrieval works without any problems.

nevertheless, JDBC retrieval causes a 'Bad BigDecimal Exception' beeing
thrown for cases when there are non- integer values in the corresponding
array.

in other words there is no problem getting a "3.0, 4.0, 5.0" array back into
java but "3.1, 4.1, 5.1" will throw a BBDE.

this behaviour is exposed - at least - by the postgresql 7.3 and the latest
production grade 7.4 JDBC drivers.

i traced things down to the 'org.postgresql.jdbc2.Array' class where i found
a line reading

AbstractJdbc2ResultSet.toBigDecimal( arrayContents[(int)index++], 0 );

in the switch/case of the base tyope for Type.NUMERIC. initializing a java
BigDecimal with a scale of '0' (the second argument in the method call)
causes an exception because for example "3.1" cannot be exactly represented
by a  BigDecimal with scale '0'.

FIX PROPOSAL:

changing the scale to '-1' ('autoscale') will allow for proper casts agains
BigDecimal and works fine for me:

AbstractJdbc2ResultSet.toBigDecimal( arrayContents[(int)index++], -1 );

hope this helps, cheers, oLiVeR.

pgsql-bugs by date:

Previous
From: Einar Indridason
Date:
Subject: Re: BUG #1191: odd usage of port 512 on localhost
Next
From: "PostgreSQL Bugs List"
Date:
Subject: BUG #1193: Some query sequences do not finish