Skip site navigation (1) Skip section navigation (2)

RE: Recursion and SPI

From: "Mikheev, Vadim" <vmikheev(at)SECTORBASE(dot)COM>
To: "'Ian Lance Taylor'" <ian(at)airs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: RE: Recursion and SPI
Date: 2001-01-05 20:44:17
Message-ID: 8F4C99C66D04D4118F580090272A7A234D322A@sectorbase1.sectorbase.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
> 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

Responses

pgsql-hackers by date

Next:From: Ian Lance TaylorDate: 2001-01-05 22:13:27
Subject: Re: Recursion and SPI
Previous:From: Alex PilosovDate: 2001-01-05 20:37:30
Subject: SHM ids (was running pgsql 7 under Jail'ed virtual machine on FreeBSD 4.2)

pgsql-patches by date

Next:From: Ian Lance TaylorDate: 2001-01-05 22:13:27
Subject: Re: Recursion and SPI
Previous:From: Alex PerelDate: 2001-01-05 19:01:09
Subject: \du in psql patch

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group