Re: Getting a primitive numeric value from "DatumGetNumeric"?

2018-02-23 Thread Demitri Muna
Hi, On Feb 22, 2018, at 9:31 PM, Michael Paquier 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

Re: Getting a primitive numeric value from "DatumGetNumeric"?

2018-02-22 Thread Tom Lane
Michael Paquier 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

Re: Getting a primitive numeric value from "DatumGetNumeric"?

2018-02-22 Thread Michael Paquier
On Thu, Feb 22, 2018 at 08:00:45PM -0500, Demitri Muna wrote: > Ah, I wasn’t aware of implicit coercion. Yes, that solves the problem > perfectly, thanks. > > 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)? I ask as

Re: Getting a primitive numeric value from "DatumGetNumeric"?

2018-02-22 Thread Demitri Muna
Hi Tom, On Feb 20, 2018, at 10:54 PM, Tom Lane wrote: > Well, the implicit coercions work in your favor in this particular case. Ah, I wasn’t aware of implicit coercion. Yes, that solves the problem perfectly, thanks. Out of curiosity, how does one read a numeric type

Re: Getting a primitive numeric value from "DatumGetNumeric"?

2018-02-20 Thread Tom Lane
Demitri Muna writes: > I’m writing a C extension for PostgreSQL. One possible input datatype for my > function is a numeric array, e.g. ARRAY[[1.5,2.5],[3.5,4.5]]. I can use > “DatumGetNumeric” to extract a “Numeric” data type from the data, but at some > point I need

Getting a primitive numeric value from "DatumGetNumeric"?

2018-02-20 Thread Demitri Muna
Hi, I’m writing a C extension for PostgreSQL. One possible input datatype for my function is a numeric array, e.g. ARRAY[[1.5,2.5],[3.5,4.5]]. I can use “DatumGetNumeric” to extract a “Numeric” data type from the data, but at some point I need to convert this to a number (e.g. double) so that