From: Demitri Muna <postgresql@demitri.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Getting a primitive numeric value from "DatumGetNumeric"?
Date: Fri, 23 Feb 2018 13:23:12 -0500
Message-ID: <66D387DA-7C49-4A32-AE92-226DB787D33C@demitri.com> (raw)
In-Reply-To: <20180223023138.GB15131@paquier.xyz>
References: <A3E2B8BE-7EE5-4555-90D8-09C832F7B558@demitri.com>
<21871.1519185281@sss.pgh.pa.us>
<19E43B98-06A3-4D78-9F86-B69D12D4BAFD@demitri.com>
<20180223023138.GB15131@paquier.xyz>
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 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: postgresql@demitri.com
Subject: Re: Getting a primitive numeric value from "DatumGetNumeric"?
In-Reply-To: <66D387DA-7C49-4A32-AE92-226DB787D33C@demitri.com>
References: <A3E2B8BE-7EE5-4555-90D8-09C832F7B558@demitri.com> <21871.1519185281@sss.pgh.pa.us> <19E43B98-06A3-4D78-9F86-B69D12D4BAFD@demitri.com> <20180223023138.GB15131@paquier.xyz> <66D387DA-7C49-4A32-AE92-226DB787D33C@demitri.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox