NaN support in NUMERIC data type - Mailing list pgsql-hackers

From Sam Mason
Subject NaN support in NUMERIC data type
Date
Msg-id 20090407155359.GG12225@frubble.xen.chris-lamb.co.uk
Whole thread Raw
Responses Re: NaN support in NUMERIC data type  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

I've just noticed that the NUMERIC input function special cases NaN
values differently to the floating point input functions.  For example
the following are all accepted (on my system anyway):
 SELECT 'NaN'::float8; SELECT ' NaN'::float8; SELECT 'NaN '::float8; SELECT '+NaN'::float8; SELECT '-NaN'::float8;

whereas only the first is OK for numeric.  Is this deliberate?

A quick check of utils/adt/numeric.c would suggest that it's been
special cased as a optimisation so we don't allocate a numeric value
in set_var_from_str() unless we need to.

As a side note; I'm only really interested in the leading/trailing
spaces.  I only noticed the leading plus/minus sign when reading the
code and think it's probably better if a NaN is rejected if it has a
leading sign.  I think it would be better if it was consistent with
FLOAT, not sure how to do this in a platform independent way though.

I could submit a patch if you want; I'm unsure whether it's better to
duplicate code in numeric_in, do slightly more work and allocate memory
for NaN's when not strictly needed, or remove knowledge of NumericVar
from numeric_in altogether and push code into set_var_from_str.
Comments?

--  Sam  http://samason.me.uk/


pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Re: [GENERAL] string_to_array with empty input
Next
From: "Hiroshi Saito"
Date:
Subject: Solution of the file name problem of copy on windows.