Value is different for AVG(CAST AS DECIMAL)

93 views
Skip to first unread message

Jane

unread,
Apr 7, 2022, 3:47:21 PM4/7/22
to H2 Database
Hi All,

I am upgrading H2 from 1.4.197 to 2.1.210. I have a query which casts a value to DECIMAL, as - SELECT AVG(CAST(A AS DECIMAL). Column A is INTEGER. 

 In older H2, this used to produce a value like 10002.5 and in 2.1.210, the same query produces 10002.0. What's happening internally here? Is there anything I can do to make this behave like in 1.0? 

The same query is being used across multiple databases (oracle, Postgres etc). That is why.

Thanks,
J.


Noel Grandin

unread,
Apr 8, 2022, 4:05:58 PM4/8/22
to H2 Database
I think you will need to cast to something like DECIMAL(20,2) i.e. specify the precision and scale

--
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 h2-database...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/66a79014-70be-47c6-9f16-7d3328a269a4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages