Re: double and numeric conversion

From: Theo Schlossnagle <jesus(at)omniti(dot)com>
To: Yeb Havinga <yebhavinga(at)gmail(dot)com>
Cc: Theo Schlossnagle <jesus(at)omniti(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: double and numeric conversion
Date: 2010-03-03 14:52:46
Message-ID: BF2CDE34-127D-4469-B663-7B02ACF7968A@omniti.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I can't release all of it, but the functions to convert uint64_t, int64_t and double to numeric Datum are the meat and I can expose those...

https://labs.omniti.com/pgsoltools/trunk/contrib/scratch/pg_type_to_numeric.c

As I mentioned, the dscale on the double_to_numeric is imperfect resulting in things like: 1.23 turning into 1.2300 in the numeric returned. This are significantly faster (as expected) than the type -> string -> numeric conversions.

On Mar 3, 2010, at 5:01 AM, Yeb Havinga wrote:

> Theo Schlossnagle wrote:
>> I didn't look deeply at the postgres internals to see if there was a way to do double -> numeric and integer-types -> numeric without intermediary string format. If that sort of thing is easy to leverage, I'd be happy to share the code.
>>
> I think your code could be valuable for postgres on the fact alone that it is almost twice as fast, and probably easy to integrate and unit test. We make heavy use of the numeric data type, so I'm very interested!
>
> regards
> Yeb Havinga
>
>

--
Theo Schlossnagle
http://omniti.com/is/theo-schlossnagle

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-03-03 15:29:34 Re: USE_LIBXSLT in MSVC builds
Previous Message Bruce Momjian 2010-03-03 14:25:29 Re: [GENERAL] to_timestamp() and quarters