Re: Problem with Numerics multiplication in C-function - Mailing list pgsql-general

From Tom Lane
Subject Re: Problem with Numerics multiplication in C-function
Date
Msg-id 16795.1249310946@sss.pgh.pa.us
Whole thread Raw
In response to Re: Problem with Numerics multiplication in C-function  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Martijn van Oosterhout <kleptog@svana.org> writes:
> On Mon, Aug 03, 2009 at 10:20:36AM -0400, Tom Lane wrote:
>> SPI_palloc is what to use to allocate the result in the right place.

> Ofcourse, and then a memcpy(). I was distracted by the fact there is an
> SPI_copy/returntuple(), but no SPI_returndatum().

Yeah, I was just thinking that that seems like an oversight.
plpgsql does this:

            if (!fcinfo->isnull && !func->fn_retbyval)
            {
                Size        len;
                void       *tmp;

                len = datumGetSize(estate.retval, false, func->fn_rettyplen);
                tmp = SPI_palloc(len);
                memcpy(tmp, DatumGetPointer(estate.retval), len);
                estate.retval = PointerGetDatum(tmp);
            }

but it seems like it'd be reasonable to provide SPI_datumcopy or
something like that to encapsulate this a bit more conveniently.

            regards, tom lane

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Problem with Numerics multiplication in C-function
Next
From: Michael Gould
Date:
Subject: Partition tables