Re: [HACKERS] numeric data type on 6.5 - Mailing list pgsql-hackers

From Thomas Lockhart
Subject Re: [HACKERS] numeric data type on 6.5
Date
Msg-id 3728790E.65B51766@alumni.caltech.edu
Whole thread Raw
In response to Re: [HACKERS] numeric data type on 6.5  (jwieck@debis.com (Jan Wieck))
Responses Re: [HACKERS] numeric data type on 6.5  (jwieck@debis.com (Jan Wieck))
List pgsql-hackers
> btw, I've got some float8->numeric conversion troubles on my
> i686/Linux box:
> postgres=> insert into t1 values ('30000000000000000000'::float8);
> INSERT 18541 1
> postgres=> select * from t1;
>                  n
> ------------------
>                  3

OK, so the problem is that large floats are printed using exponential
notation, and the float8->numeric conversion routine uses the
float8out() routine to convert to a string in preparation for
ingestion as a numeric type. I've modified my copy of float8_numeric()
to instead print directly into a (large!) buffer using the "%f"
specifier, to ensure that the string is always compatible with the
numeric reader:

postgres=> create table t1 (f float8, n numeric(20,2), d
decimal(20,2));
CREATE
postgres=> insert into t1 values (300.1);
INSERT 18641 1
postgres=> insert into t1 values (300000000000000000);
INSERT 18642 1
postgres=> update t1 set n = f, d = f;
UPDATE 2
postgres=> select * from t1;
f    |                    n|                    d
-----+---------------------+---------------------
300.1|               300.10|               300.10
3e+17|300000000000000000.00|300000000000000000.00
(2 rows)

The float8_numeric() code already had checked for NULL and NaN, so I
think this does not lose functionality. What do you think Jan? Should
I make the change? Or is there another way??
                     - Tom

-- 
Thomas Lockhart                lockhart@alumni.caltech.edu
South Pasadena, California


pgsql-hackers by date:

Previous
From: Martin Weinberg
Date:
Subject: Help/advice/suggestions on query optimizer for a large table
Next
From: jwieck@debis.com (Jan Wieck)
Date:
Subject: Re: [HACKERS] numeric data type on 6.5