pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedBad value for type BigDecimal : Infinity
4+ messages / 3 participants
[nested] [flat]
* Bad value for type BigDecimal : Infinity
@ 2021-07-08 18:37 Ivan Petrov <capacytron@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Ivan Petrov @ 2021-07-08 18:37 UTC (permalink / raw)
To: pgsql-admin@lists.postgresql.org
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
at
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at
org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1541)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:393)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:465)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:475)
...
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)
at org.postgresql.jdbc.PgResultSet.getBigDecimal(PgResultSet.java:2443)
at org.postgresql.jdbc.PgResultSet.getBigDecimal(PgResultSet.java:406)
What is the right way to debug it? Column name would help...
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bad value for type BigDecimal : Infinity
@ 2021-07-08 19:45 Tom Lane <tgl@sss.pgh.pa.us>
parent: Ivan Petrov <capacytron@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2021-07-08 19:45 UTC (permalink / raw)
To: Ivan Petrov <capacytron@gmail.com>; +Cc: pgsql-jdbc@lists.postgresql.org
[ 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bad value for type BigDecimal : Infinity
@ 2021-07-09 13:52 Sehrope Sarkuni <sehrope@jackdb.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: Sehrope Sarkuni @ 2021-07-09 13:52 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Ivan Petrov <capacytron@gmail.com>; pgsql-jdbc@lists.postgresql.org
>
> 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/
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Bad value for type BigDecimal : Infinity
@ 2021-07-10 09:36 Ivan Petrov <capacytron@gmail.com>
parent: Sehrope Sarkuni <sehrope@jackdb.com>
0 siblings, 0 replies; 4+ messages in thread
From: Ivan Petrov @ 2021-07-10 09:36 UTC (permalink / raw)
To: Sehrope Sarkuni <sehrope@jackdb.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-jdbc@lists.postgresql.org
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/
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-07-10 09:36 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 18:37 Bad value for type BigDecimal : Infinity Ivan Petrov <capacytron@gmail.com>
2021-07-08 19:45 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-07-09 13:52 ` Sehrope Sarkuni <sehrope@jackdb.com>
2021-07-10 09:36 ` Ivan Petrov <capacytron@gmail.com>
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