From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Michael Paquier <michael(at)paquier(dot)xyz> |
Cc: | Demitri Muna <postgresql(at)demitri(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Getting a primitive numeric value from "DatumGetNumeric"? |
Date: | 2018-02-23 04:25:39 |
Message-ID: | 16882.1519359939@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Michael Paquier <michael(at)paquier(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Vinodh NV | 2018-02-23 04:43:01 | Postgres hangs for the query "lock table <Tablename> in exclusive mode" |
Previous Message | David Rowley | 2018-02-23 04:10:56 | Re: Not sure if I should CREATE INDEX for text columns on which I plan to filter later |