In Postgres 14, I see rounded results that do not make sense to me. Trying to understand what is going on. In all cases I am dividing 19 by 3.
Casting either integer
value to a real
:
SELECT 19::real /3;
yields a value of 6.333333333333333
SELECT 19/3::real;
yields a value of 6.333333333333333
However, casting both sides to real
yields:
SELECT 19::real/3::real;
yields a value of 6.3333335
Interestingly enough, if I cast both sides to double precision
or float
, the answer is 6.333333333333333
Also
SELECT 19.0 / 3.0;
yields 6.333333333333333
SELECT 19.0::real / 3.0::real;
yields 6.3333335
SELECT ( 16.0 / 3.0) :: real;
yields 6.3333335
I now see that:
SELECT 6.333333333333333::real;
yields 6.33333335
So the real issue seems to be:
Why are we rounding in this weird way (I know that real / floats are inexact but this seems extreme.)
What data type is
19::real / 3;