pgsql-7.4.2
I think it's not a bug, just interesting results:
SELECT 9223372036854775807/(365*10000000) ;
result: -14300526699
wrong
SELECT ( 9223372036854775807/365 )/10000000 ;
result: 2526951242
good
SELECT ( 9223372036854775807::real /(365*10000000) ) ;
result: -14300526699,6589
wrong
SELECT ( 9223372036854775807 /(365*10000000)::real ) ;
result: -14300526699,6589
wrong
SELECT ( 9223372036854775807 /(365*10000000)::real ) ;
result: -14300526699,6589
wrong
SELECT ( 9223372036854775807/(365*10000000::real) ) ;
result: 2526951242,97391
good
SELECT ( 9223372036854775807/(365::real*10000000) ) ;
result: 2526951242,97391
good
REASON IS:
SELECT 365*10000000 ;
result: -644967296
wrong
but
SELECT 365*10000000::int8 ;
result: 3650000000
good
If this operation embended in complex expression,
then very difficult to find the reason of computation error.
This misstake comes only after the border of int4 and int8.
-------------------------------------------------
Gyenese Pál Attila
számítástechnikai vezető
MEDIAGNOST KFT.
1106 Fehér út 10
Tel.: 431.87.74
Fax.: 265.20.73