| From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
|---|---|
| To: | Ilya Urikh <ilya(dot)urikh(at)gmail(dot)com> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Problem with Numerics multiplication in C-function |
| Date: | 2009-08-03 06:42:38 |
| Message-ID: | 20090803064238.GB1487@svana.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Mon, Aug 03, 2009 at 01:45:53PM +1100, Ilya Urikh wrote:
> Hi, I have a strange problem with Numeric multiplication in C-function.
>
> There are 2 functions getRate and getVAT which return Numeric. In 3rd
> function calculateService I try to multiply the results of getRate and
> getVAT. After execution I have two types of error, some time without
> messages and with message "Invalid memory alloc ... ".
> If I initialize the Numeric variables inside calculateService and multiply,
> function numeric_mul works fine.
Not entirly sure, but I think it's because SPI_finish destroys the SPI
memory context, including the data in it, which is the data you are
trying to return. See this page in the documentation:
http://www.postgresql.org/docs/8.3/interactive/spi-memory.html
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().
Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chris Black | 2009-08-03 07:30:31 | Out of Office AutoReply: Never thought he would be able |
| Previous Message | sweta | 2009-08-03 06:24:52 | Re: Drop Cluster |