Thread: Re: Bad value for type BigDecimal : Infinity

Re: Bad value for type BigDecimal : Infinity

From
Tom Lane
Date:
[ redirecting to jdbc list ]

Ivan Petrov <capacytron@gmail.com> writes:
> Hi, I'm using postgres JDBC driver version 42.2.23
> https://mvnrepository.com/artifact/org.postgresql/postgresql/42.2.23
> Here is my exception

> Bad value for type BigDecimal : Infinity; nested exception is
> org.postgresql.util.PSQLException: Bad value for type BigDecimal : Infinity
> ...
> Caused by: org.postgresql.util.PSQLException: Bad value for type BigDecimal
> : Infinity
> at org.postgresql.jdbc.PgResultSet.toBigDecimal(PgResultSet.java:3064)
> at org.postgresql.jdbc.PgResultSet.toBigDecimal(PgResultSet.java:3073)
> at org.postgresql.jdbc.PgResultSet.getNumeric(PgResultSet.java:2491)

I dunno, does BigDecimal have a concept of infinity?  If not, this
doesn't seem like something the driver can avoid for you.  If it
does, then something needs to be updated to be aware that PG now
supports infinities in type numeric.

            regards, tom lane



Re: Bad value for type BigDecimal : Infinity

From
Sehrope Sarkuni
Date:
Ivan Petrov <capacytron@gmail.com> writes:
> Hi, I'm using postgres JDBC driver version 42.2.23
> https://mvnrepository.com/artifact/org.postgresql/postgresql/42.2.23
> Here is my exception

> Bad value for type BigDecimal : Infinity; nested exception is
> org.postgresql.util.PSQLException: Bad value for type BigDecimal : Infinity
> ...
> Caused by: org.postgresql.util.PSQLException: Bad value for type BigDecimal
> : Infinity
> at org.postgresql.jdbc.PgResultSet.toBigDecimal(PgResultSet.java:3064)
> at org.postgresql.jdbc.PgResultSet.toBigDecimal(PgResultSet.java:3073)
> at org.postgresql.jdbc.PgResultSet.getNumeric(PgResultSet.java:2491)

On Thu, Jul 8, 2021 at 3:45 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: 
I dunno, does BigDecimal have a concept of infinity?  If not, this
doesn't seem like something the driver can avoid for you.  If it
does, then something needs to be updated to be aware that PG now
supports infinities in type numeric.

No, there's no way to represent +/- Infinity with a BigDecimal in Java and the driver does not have a way to deal with those values.

To read those columns, you have to call ResultSet.getString(...) and inspect that value before retrieving it as a BigDecimal.

Because of the automatic type conversions, you can run into this same issue if you call ResultSet.getBigDecimal(...) on a float column that has that a +/- Infinity value.

It's the same issue with retrieving 'NaN'::numeric as a BigDecimal. You'll get an exception as the Java type does not have a representation.

If there's a chance the values cannot be represented as BigDecimal you'll have to fetch the String value and then go from there.

 Regards,
-- Sehrope Sarkuni
Founder & CEO | JackDB, Inc. | https://www.jackdb.com/

Re: Bad value for type BigDecimal : Infinity

From
Ivan Petrov
Date:
Got it, thank you.

пт, 9 июл. 2021 г. в 14:53, Sehrope Sarkuni <sehrope@jackdb.com>:
Ivan Petrov <capacytron@gmail.com> writes:
> Hi, I'm using postgres JDBC driver version 42.2.23
> https://mvnrepository.com/artifact/org.postgresql/postgresql/42.2.23
> Here is my exception

> Bad value for type BigDecimal : Infinity; nested exception is
> org.postgresql.util.PSQLException: Bad value for type BigDecimal : Infinity
> ...
> Caused by: org.postgresql.util.PSQLException: Bad value for type BigDecimal
> : Infinity
> at org.postgresql.jdbc.PgResultSet.toBigDecimal(PgResultSet.java:3064)
> at org.postgresql.jdbc.PgResultSet.toBigDecimal(PgResultSet.java:3073)
> at org.postgresql.jdbc.PgResultSet.getNumeric(PgResultSet.java:2491)

On Thu, Jul 8, 2021 at 3:45 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: 
I dunno, does BigDecimal have a concept of infinity?  If not, this
doesn't seem like something the driver can avoid for you.  If it
does, then something needs to be updated to be aware that PG now
supports infinities in type numeric.

No, there's no way to represent +/- Infinity with a BigDecimal in Java and the driver does not have a way to deal with those values.

To read those columns, you have to call ResultSet.getString(...) and inspect that value before retrieving it as a BigDecimal.

Because of the automatic type conversions, you can run into this same issue if you call ResultSet.getBigDecimal(...) on a float column that has that a +/- Infinity value.

It's the same issue with retrieving 'NaN'::numeric as a BigDecimal. You'll get an exception as the Java type does not have a representation.

If there's a chance the values cannot be represented as BigDecimal you'll have to fetch the String value and then go from there.

 Regards,
-- Sehrope Sarkuni
Founder & CEO | JackDB, Inc. | https://www.jackdb.com/