Bug #627:

Started by PostgreSQL Bugs Listabout 24 years ago3 messagesbugs
Jump to latest
#1PostgreSQL Bugs List
pgsql-bugs@postgresql.org

Harish Rao (rao.harish@acm.org) reports a bug with a severity of 4
The lower the number the more severe it is.

Short Description

Long Description
create table t1 (f1 real);
insert into t1 values(1.01);
select * from t1 where f1 > 1.01;

Sample Code
create table t1 (f1 real);
insert into t1 values(1.01);
select * from t1 where f1 > 1.01;

No file was uploaded with this report

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: PostgreSQL Bugs List (#1)
Re: Bug #627:

On Fri, 29 Mar 2002 pgsql-bugs@postgresql.org wrote:

Harish Rao (rao.harish@acm.org) reports a bug with a severity of 4
The lower the number the more severe it is.

Short Description

Long Description
create table t1 (f1 real);
insert into t1 values(1.01);
select * from t1 where f1 > 1.01;

What's the bug here? An explanation would
be useful.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: PostgreSQL Bugs List (#1)
Re: Bug #627:

pgsql-bugs@postgresql.org writes:

create table t1 (f1 real);
insert into t1 values(1.01);
select * from t1 where f1 > 1.01;

regression=# create table t1 (f1 real);
CREATE
regression=# insert into t1 values(1.01);
INSERT 139787 1
regression=# select * from t1 where f1 > 1.01;
f1
----
(0 rows)

And your point was?

BTW, if you were going to complain that on your platform the SELECT
returns the row, don't bother. Float comparisons are inherently
inaccurate.

You might, however, find that the behavior is less surprising if you do
the comparison against a float4 (== real) rather than float8 constant:

select * from t1 where f1 > '1.01'::real;

The query as you wrote it will convert the original 1.01 to float4
for storage and then to float8 for comparison against the second 1.01
(which never becomes float4), so a little bit of roundoff error is
likely to creep in.

regards, tom lane