Re: numeric and float comparison oddities

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: numeric and float comparison oddities
Дата
Msg-id 1405.1406906075@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: numeric and float comparison oddities  (Kevin Grittner <kgrittn@ymail.com>)
Ответы Re: numeric and float comparison oddities  (Kevin Grittner <kgrittn@ymail.com>)
Список 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 по дате отправления:

Предыдущее
От: Kevin Grittner
Дата:
Сообщение: Re: numeric and float comparison oddities
Следующее
От: Thomas Munro
Дата:
Сообщение: Re: SKIP LOCKED DATA (work in progress)