calling plpgsql from c
Hallo,
I'm trying to call plpgsql functions from c functions directly through
the Oid, but i have a problem: it seems that the plpgsql interpreter
calls SPI_connect and fails even if the caller has already
spi-connected. I am working on recursive functions in c and so i can not
call SPI_finish by myself before calling the plpgsql function since i
would loose tons of stuff (or am i missing something?). Now, is there a
way to work around this? If not: wouldn't it be meaningful to change
this behavior?
thank you
max.
Max Jacob <Max.Jacob@ircam.fr> writes:
I'm trying to call plpgsql functions from c functions directly through
the Oid, but i have a problem: it seems that the plpgsql interpreter
calls SPI_connect and fails even if the caller has already
spi-connected.
This is a safety check. If you are connected to SPI, you need to call
SPI_push() and SPI_pop() around any operation that might involve
recursive use of SPI. That helps delimit "your" calls versus "their"
calls versus "no man's land".
It does seem that this is quite undocumented though. Jan?
regards, tom lane
Tom Lane wrote:
Max Jacob <Max.Jacob@ircam.fr> writes:
I'm trying to call plpgsql functions from c functions directly through
the Oid, but i have a problem: it seems that the plpgsql interpreter
calls SPI_connect and fails even if the caller has already
spi-connected.This is a safety check. If you are connected to SPI, you need to call
SPI_push() and SPI_pop() around any operation that might involve
recursive use of SPI. That helps delimit "your" calls versus "their"
calls versus "no man's land".It does seem that this is quite undocumented though. Jan?
I have documented SPI_push() and SPI_pop() with the attached SGML patch.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073