Consider the following table:

CREATE TABLE foo (
 id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL
 , PRIMARY KEY(id)
);

The following query executed directly using the H2 console works fine:

SELECT
  COUNT(*)
FROM
  foo
WHERE
  id <> COALESCE (-9223372036854775808, 0)

However, the same query does not work when executed as a *PreparedStatement*, 
throwing the following exception:

Caused by: org.h2.jdbc.JdbcSQLException: Numeric value out of range: 
"-9223372036854775808"; SQL statement:
select count(id) from foo where id<>coalesce(?, 0)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.value.Value.convertToInt(Value.java:1069)
at org.h2.value.Value.convertTo(Value.java:621)
at org.h2.expression.Function.getSimpleValue(Function.java:1020)
at org.h2.expression.Function.getValueWithArgs(Function.java:1195)
at org.h2.expression.Function.getValue(Function.java:590)
at org.h2.expression.Comparison.getValue(Comparison.java:257)
at org.h2.expression.ConditionAndOr.getValue(ConditionAndOr.java:86)
at org.h2.expression.Expression.getBooleanValue(Expression.java:178)
at org.h2.command.dml.Select.queryGroup(Select.java:338)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:650)
at org.h2.command.dml.Query.query(Query.java:341)
at org.h2.command.dml.Query.query(Query.java:309)
at org.h2.command.dml.Query.query(Query.java:36)
at org.h2.command.CommandContainer.query(CommandContainer.java:113)
at org.h2.command.Command.executeQuery(Command.java:201)
at 
org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:110)


Debugging shows that the method *convertToInt* in the class *Value* is 
called as *convertToInt(valueLong.getLong())*. Naturally, this would lead 
to the specified exception since some long values will not fit within the 
storage space of ints.

Is there a specific reason why *convertToInt* is called in this case? 
Shouldn't the long value be used directly?

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to