Hi,
According to the SUM() documentation.
> the returned value is of the same data type as the parameter.
>
However it seems to not be the case (version 1.3.170).
Here is the test case:
private static int getJdbcType(Connection conn, String sql) throws
SQLException {
PreparedStatement st = conn.prepareStatement(sql);
try {
ResultSet rs = st.executeQuery();
try {
return rs.getMetaData().getColumnType(1);
} finally {
rs.close();
}
} finally {
st.close();
}
}
private static void doUpdate(Connection conn, String sql) throws
SQLException {
PreparedStatement st = conn.prepareStatement(sql);
try {
st.executeUpdate();
} finally {
st.close();
}
}
public static void main(String[] args) {
try {
Connection conn =
DriverManager.getConnection("jdbc:h2:mem:test");
try {
doUpdate(conn,"create table test (col BIGINT)");
System.out.println(getJdbcType(conn, "select col from
test"));
System.out.println(getJdbcType(conn, "select sum(col) from
test")); // wrong !
System.out.println(getJdbcType(conn, "select cast(sum(col)
as BIGINT) from test")); // workarround
} finally {
conn.close();
}
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
*
The result is:*
-5 // java.sql.BIGINT
3 // java.sql.DECIMAL
-5 // java.sql.BIGINT
*Expected result:*
-5 // java.sql.BIGINT
-5 // java.sql.BIGINT
-5 // java.sql.BIGINT
I think it is a bug, the mapped JDBC type returned by ResultSetMetaData
should not change for all queries.
Regards,
Cédric.
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/h2-database?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.