From: | Demitri Muna <postgresql(at)demitri(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Getting a primitive numeric value from "DatumGetNumeric"? |
Date: | 2018-02-23 18:23:12 |
Message-ID: | 66D387DA-7C49-4A32-AE92-226DB787D33C@demitri.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
On Feb 22, 2018, at 9:31 PM, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> PG_GETARG_NUMERIC(), no?
That function returns an object of datatype “Numeric” which still requires some (not immediately obvious) conversation to a 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 pointed out, implicit coercion handles what I need so I’ll stick with that.
Cheers,
Demitri
From | Date | Subject | |
---|---|---|---|
Next Message | Demitri Muna | 2018-02-23 18:35:31 | Location to specify C compiler option in C extension |
Previous Message | Andres Freund | 2018-02-23 17:20:02 | Re: PQConsumeinput stuck on recv |