Subject: org.postgresql.util.PSQLException: ERROR: value out of range: underflow

From: Thomas Markus <[email-masked]>
Date: Sun, 6 Feb 2022 10:07:15 +0100

Hello

a customer got the exception "org.postgresql.util.PSQLException: ERROR: 
value out of range: underflow" without any stacktrace etc.
System is Linux with PG 12.2

Once I got a similar error in Oracle so I checked double values for edge 
cases (see below) but without success. This message is also not part of 
pgjdbc.

Has anyone any idea where this message may originate from? The only used 
datatypes for numbers are bigint, integer and double precision.

Thanks
Thomas

Test:

try (Statement s = c.createStatement()) {
     s.executeUpdate("create table x (x double precision)");
}
try (PreparedStatement p = c.prepareStatement("insert into x (x) values 
(?)")) {

     p.setDouble(1, Double.MIN_VALUE);
     p.executeUpdate();

     p.setDouble(1, -Double.MIN_VALUE);
     p.executeUpdate();

     p.setDouble(1, Double.MIN_NORMAL);
     p.executeUpdate();

     p.setDouble(1, -Double.MIN_NORMAL);
     p.executeUpdate();

     p.setDouble(1, Double.MAX_VALUE);
     p.executeUpdate();

     p.setDouble(1, -Double.MAX_VALUE);
     p.executeUpdate();

     p.setDouble(1, Double.NEGATIVE_INFINITY);
     p.executeUpdate();

     p.setDouble(1, Double.POSITIVE_INFINITY);
     p.executeUpdate();

     p.setDouble(1, Double.NaN);
     p.executeUpdate();

}

---

From: Tom Lane <[email-masked]>
Date: Sun, 06 Feb 2022 11:45:43 -0500

> value out of range: underflow" without any stacktrace etc.

I'd venture that the cause is some server-side double precision
arithmetic that underflowed.  It's not that hard to hit, eg

postgres=# select 1e-200::float8 * 1e-200::float8;
ERROR:  value out of range: underflow

			regards, tom lane

---

From: Dave Cramer <[email-masked]>
Date: Sun, 6 Feb 2022 13:25:36 -0500

> ERROR:  value out of range: underflow
I mistakenly responded privately and OP responded to that.

Turns out a column was added with the wrong type.

Dave

---

From: Thomas Markus <[email-masked]>
Date: Mon, 7 Feb 2022 06:39:15 +0100

> ERROR:  value out of range: underflow
Dave answered private here:

A double in java cant hold such big numbers. In fits fine in float8
Here one of our developers added a float4 column manually instead of 
float8. With float4 its easy to force that error.

regards
Thomas