I resolved this problem with following strings in getRate:
result = SPI_palloc(sizeof(rate));
memcpy(result, rate, sizeof(rate));
P.S. I think it's a good idea to add example to documentation. Anyway when I had started to work with PostgreSQL I was very surprised at so clear and structured documentation. :)
On Tue, Aug 4, 2009 at 1:44 AM, Martijn van Oosterhout <kleptog@xxxxxxxxx> wrote:
On Mon, Aug 03, 2009 at 10:20:36AM -0400, Tom Lane wrote:Ofcourse, and then a memcpy(). I was distracted by the fact there is an
> Martijn van Oosterhout <kleptog@xxxxxxxxx> writes:
> > What you need to do is copy the Datum you wish to return into the upper
> > memory context. I'm not seeing a helpful SPI utility function or
> > obvious example here you help you, but I'm sure it's something with
> > MemoryContextSwitchTo() and datumCopy().
>
> SPI_palloc is what to use to allocate the result in the right place.
SPI_copy/returntuple(), but no SPI_returndatum(). It might actually be
helpful to include in the documentation an example of returning from a
function a result from SPI, since it's not entirely obvious.
Have a nice day,
--
Martijn van Oosterhout <kleptog@xxxxxxxxx> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iD8DBQFKdvezIB7bNG8LQkwRAiwGAJ0dyrP+JROL9F/OhKvzLlR5O2h4tACdEIAE
QvCDFfLfnzCpkti8PXcVp38=
=ZXiG
-----END PGP SIGNATURE-----
--
Best regards,
Ilya Urikh.