Tom Lane wrote:
>
> "Frederick W. Reimer" <fwr@ga.prestige.net> writes:
> > In general, it's recommended you don't check for exact equivalence when
> > doing calculations on real numbers and instead check for "almost exactness."
>
perhaps "where trunc(85/0.0085) = 10000" works better.
> Or use datatype NUMERIC, which behaves in a more intuitive way (at least
> for people who are accustomed to thinking in decimal). But yes, exact
> equality checks on float values are usually foolish.
But ...
hannu=# create table ntest(n numeric(3), n1 numeric(6,4));
CREATE
hannu=# insert into ntest values(80, 80/10000);
INSERT 311338 1
hannu=# insert into ntest values(81, 81/10000);
INSERT 311339 1
hannu=# select count(*) from ntest where n/n1 = 10000;
ERROR: division by zero on numeric
hannu=# select * from ntest;n | n1
----+--------80 | 0.000081 | 0.0000
eek !
I understand why this is so, but should it be ?
Can't we assume that 80/10000 is numeric and back-propagate that
knowledge to constituents so that 80 and 10000 are also considered
numetics.
Or even better assume that 80/10000 is a rational number ;)
-------------------
Hannu