BUG #1192: JDBC driver: org.postgresql.jdbc2.Array throws Bad BigDecimal Exception

From: "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1192: JDBC driver: org.postgresql.jdbc2.Array throws Bad BigDecimal Exception
Date: 2004-07-14 07:12:55
Message-ID: 20040714071255.90742CF49E3@www.postgresql.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

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

Email address: oliver(at)arachnerd(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PostgreSQL Bugs List 2004-07-14 13:38:55 BUG #1193: Some query sequences do not finish
Previous Message Nicolas Bottarini 2004-07-13 14:44:54 Replace function BUG