From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael@paquier.xyz>
Cc: Demitri Muna <postgresql@demitri.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Getting a primitive numeric value from "DatumGetNumeric"?
Date: Thu, 22 Feb 2018 23:25:39 -0500
Message-ID: <16882.1519359939@sss.pgh.pa.us> (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>
Michael Paquier <michael@paquier.xyz> writes:
> On Thu, Feb 22, 2018 at 08:00:45PM -0500, Demitri Muna wrote:
>> Out of curiosity, how does one read a numeric type from within a C
>> extension (i.e. get a number value out of the Datum type)?
> PG_GETARG_NUMERIC(), no?
I think the core point here is that PG's "numeric" type *isn't* any
primitive C type; it's a variable-length BCD encoding. If you want
to deal with it you can, but you must spend some time reading
src/backend/utils/adt/numeric.c, as Michael suggests. If you just
want a convenient C approximation, then work with float8 and let
the implicit-coercion machinery do the conversion for you.
regards, tom lane
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: tgl@sss.pgh.pa.us, michael@paquier.xyz, postgresql@demitri.com
Subject: Re: Getting a primitive numeric value from "DatumGetNumeric"?
In-Reply-To: <16882.1519359939@sss.pgh.pa.us>
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> <16882.1519359939@sss.pgh.pa.us>
* 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