numeric and float comparison oddities

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: numeric and float comparison oddities
Date: 2014-08-01 06:33:44
Message-ID: 1406874824.15301.47.camel@jeff-desktop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2014-08-01 07:26:53 Re: gaussian distribution pgbench -- splits v4
Previous Message Amit Kapila 2014-08-01 03:35:33 Re: Proposal: Incremental Backup