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