Does the SPI interface support recursion?  That is, can a function
use SPI to make a query which involves calling another function which
uses SPI?

The documentation suggests not, saying that if a function which uses
SPI calls another function which uses SPI, it won't work, and calling
that ``bad practice.''

However, in spi.c I note that there is a stack, and a variable
_SPI_curid, and the undocumented functions SPI_push and SPI_pop.  If
that works to support recursion, then why does the documentation
recommend against it?


Are there any restrictions on when SPI_connect may be called?  The
executor can presumably call a function at any time during the
execution of a plan if the function is used in a WHERE clause.  If
that function turns around and calls the executor via SPI, are there
any possibilities for deadlock?

Ian

5 Jan 2001 11:39:16 -0800
Ian Lance Taylor <ian@airs.com>
Recursion and SPI
Ian Lance Taylor <ian@airs.com> writes:
> Does the SPI interface support recursion?  That is, can a function
> use SPI to make a query which involves calling another function which
> uses SPI?

Looks to me like it should work.

> The documentation suggests not, saying that if a function which uses
> SPI calls another function which uses SPI, it won't work, and calling
> that ``bad practice.''

The documentation could be out of date.  Why don't you test it out and
let us know?

			regards, tom lane

Fri, 05 Jan 2001 18:03:54 -0500
Tom Lane <tgl@sss.pgh.pa.us>
Re: Recursion and SPI 