RE: Recursion and SPI

Поиск
Список
Период
Сортировка
От Mikheev, Vadim
Тема RE: Recursion and SPI
Дата
Msg-id 8F4C99C66D04D4118F580090272A7A234D322A@sectorbase1.sectorbase.com
обсуждение исходный текст
Ответ на Recursion and SPI  (Ian Lance Taylor <ian@airs.com>)
Список pgsql-hackers
> 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?

From http://www.postgresql.org/docs/programmer/spi.htm :

"SPI procedures are always called by some (upper) Executor and the SPI
manager
uses the Executor to run your queries. Other procedures may be called by the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Executor running queries from your procedure."

> 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.''

From http://www.postgresql.org/docs/programmer/spi-spiconnect.htm :

"You may get SPI_ERROR_CONNECT error if SPI_connect is called from an
already
connected procedure - e.g. if you *directly call* one procedure from another
^^^^^^^^^^^^^^^
connected one. Actually, while the child procedure will be able to use SPI,
your parent procedure will not be able to continue to use SPI after the
child
returns (if SPI_finish is called by the child). It's bad practice."

But you are able to run queries which call SPI functions.

> 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?

Afair, there were no SPI_push & SPI_pop originally. Someone added them
but forgot to document.

Vadim


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Ian Lance Taylor
Дата:
Сообщение: Recursion and SPI
Следующее
От: Ian Lance Taylor
Дата:
Сообщение: Re: Recursion and SPI