Re: numeric and float comparison oddities - Mailing list pgsql-hackers

From Tom Lane
Subject Re: numeric and float comparison oddities
Date
Msg-id 1405.1406906075@sss.pgh.pa.us
Whole thread Raw
In response to Re: numeric and float comparison oddities  (Kevin Grittner <kgrittn@ymail.com>)
Responses Re: numeric and float comparison oddities
List pgsql-hackers
Kevin Grittner <kgrittn@ymail.com> writes:
> Jeff Davis <pgsql@j-davis.com> wrote:
>> I saw some strange results:

> The part I find strange is that the first one evaluates to true,
> since numeric can exactly represent 1.1 and float8 cannot.

The reason is that the numeric input is converted to float8 for
comparison:

regression=# create table ttt(f4 float4, f8 float8, fn numeric);
CREATE TABLE
regression=# explain verbose select f4=fn, f8=fn from ttt;                              QUERY PLAN
        
 
------------------------------------------------------------------------Seq Scan on public.ttt  (cost=0.00..32.00
rows=1100width=44)  Output: (f4 = (fn)::double precision), (f8 = (fn)::double precision)Planning time: 0.325 ms
 
(3 rows)

Were it not, you'd hardly ever get equality.

I think that years ago we concluded this behavior was required by
SQL spec (see the language about exact vs inexact numeric types).
        regards, tom lane



pgsql-hackers by date:

Previous
From: Kevin Grittner
Date:
Subject: Re: numeric and float comparison oddities
Next
From: Thomas Munro
Date:
Subject: Re: SKIP LOCKED DATA (work in progress)