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

From Ilya Urikh
Subject Re: Problem with Numerics multiplication in C-function
Date
Msg-id adf175f70908031518t29ceba0fr18116e82e931903c@mail.gmail.com
Whole thread Raw
In response to Re: Problem with Numerics multiplication in C-function  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
Thank's a lot! That's really help. I failed to bear memory context switching in mind.
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@svana.org> wrote:
On Mon, Aug 03, 2009 at 10:20:36AM -0400, Tom Lane wrote:
> Martijn van Oosterhout <kleptog@svana.org> 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.

Ofcourse, and then a memcpy(). I was distracted by the fact there is an
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@svana.org>   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.

pgsql-general by date:

Previous
From: Andreas Kalsch
Date:
Subject: Re: character 0xe29986 of encoding "UTF8" has no equivalent in "LATIN2"
Next
From: Alban Hertroys
Date:
Subject: Re: character 0xe29986 of encoding "UTF8" has no equivalent in "LATIN2"