[HACKERS] numeric and float comparison oddities

2014-08-01 Thread Jeff Davis
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

Re: [HACKERS] numeric and float comparison oddities

2014-08-01 Thread Kevin Grittner
Jeff Davis pg...@j-davis.com wrote: 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) The part I find strange is that the first one evaluates to

Re: [HACKERS] numeric and float comparison oddities

2014-08-01 Thread Tom Lane
Kevin Grittner kgri...@ymail.com writes: Jeff Davis pg...@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

Re: [HACKERS] numeric and float comparison oddities

2014-08-01 Thread Kevin Grittner
Tom Lane t...@sss.pgh.pa.us wrote: Kevin Grittner kgri...@ymail.com writes: Jeff Davis pg...@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

Re: [HACKERS] numeric and float comparison oddities

2014-08-01 Thread Tom Lane
Kevin Grittner kgri...@ymail.com writes: It would be more consistent, ISTM, to cast float8 to float4 when those are compared, and to cast numeric to whichever type is on the other side of the comparison operator. I would vote against that on the grounds of greatly increased risk of overflow

Re: [HACKERS] numeric and float comparison oddities

2014-08-01 Thread Kevin Grittner
Tom Lane t...@sss.pgh.pa.us wrote: Kevin Grittner kgri...@ymail.com writes: It would be more consistent, ISTM, to cast float8 to float4 when those are compared, and to cast numeric to whichever type is on the other side of the comparison operator. I would vote against that on the grounds of