Re: Getting a primitive numeric value from "DatumGetNumeric"? - Mailing list pgsql-general

From Demitri Muna
Subject Re: Getting a primitive numeric value from "DatumGetNumeric"?
Date
Msg-id 66D387DA-7C49-4A32-AE92-226DB787D33C@demitri.com
Whole thread Raw
In response to Re: Getting a primitive numeric value from "DatumGetNumeric"?  (Michael Paquier <michael@paquier.xyz>)
List pgsql-general
Hi,

On Feb 22, 2018, at 9:31 PM, Michael Paquier <michael@paquier.xyz> wrote:

> PG_GETARG_NUMERIC(), no?

That function returns an object of datatype “Numeric” which still requires some (not immediately obvious) conversation
toa double (or whatever primitive C type). 

> When working on implementing your own data
> types or when hacking out functions which manipulate arguments of an
> existing datatype, looking at the input and output functions help a
> lot.  In your case, numeric_in and numeric_out in
> src/backend/utils/adt/numeric.c is full of hints.

I spent an hour diving into the code out of curiosity. I found useful functions like this:

double numeric_to_double_no_overflow(Numeric n)

They’re available from the PostgreSQL main source code, but not exposed in the public headers. (Maybe I was missing
something.)There was enough there where I could see a way to copy/paste or otherwise link to those methods, but as Tom
pointedout, implicit coercion handles what I need so I’ll stick with that. 

Cheers,
Demitri



pgsql-general by date:

Previous
From: Andres Freund
Date:
Subject: Re: PQConsumeinput stuck on recv
Next
From: Demitri Muna
Date:
Subject: Location to specify C compiler option in C extension