numeric and float comparison oddities - Mailing list pgsql-hackers

From Jeff Davis
Subject numeric and float comparison oddities
Date
Msg-id 1406874824.15301.47.camel@jeff-desktop
Whole thread Raw
Responses Re: numeric and float comparison oddities
List pgsql-hackers
I saw some strange results:

postgres=# select '1.1'::numeric = '1.1'::float8;?column? 
----------t
(1 row)

postgres=# select '1.1'::numeric = '1.1'::float4;?column? 
----------f
(1 row)

When I looked into it, I saw that the numeric is being cast to a float8,
making the first statement trivially true. 

Why does the cast go from numeric to float if that direction loses
precision? One reason is because float supports +/- infinity, but that
seems more like convenience than a good reason. Is there another reason?

Have we considered adding +/- infinity to numeric so that it can
represent every float value? That might make the numeric hierarchy a
little cleaner and less surprising.

Regards,Jeff Davis





pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Proposal: Incremental Backup
Next
From: Fabien COELHO
Date:
Subject: Re: gaussian distribution pgbench -- splits v4