Re: [HACKERS] numeric data type on 6.5

From: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
To: Jan Wieck <jwieck(at)debis(dot)com>, t-ishii(at)sra(dot)co(dot)jp, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] numeric data type on 6.5
Date: 1999-04-29 15:21:51
Message-ID: 3728790E.65B51766@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)alumni(dot)caltech(dot)edu
South Pasadena, California

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message José Soares 1999-04-29 15:45:10 Re: [SQL] LIMIT
Previous Message Martin Weinberg 1999-04-29 15:21:41 Help/advice/suggestions on query optimizer for a large table