Plan Management

SPI_prepare

SPI_prepare creates and returns an execution plan (parser+planner+optimizer) but does not execute the query.

SPI_prepare(query, nargs, argtypes)

SPI_saveplan

SPI_saveplan stores a plan prepared by SPI_prepare in safe memory protected from freeing by SPI_finish or the transaction manager.

SPI_saveplan(plan)

Outputs

void *

Execution plan location. NULL if unsuccessful.

SPI_result

SPI_ERROR_ARGUMENT if plan is NULL
SPI_ERROR_UNCONNECTED if procedure is un-connected

SPI_execp

SPI_execp stores a plan prepared by SPI_prepare in safe memory protected from freeing by SPI_finish or the transaction manager.

SPI_execp(plan, values, nulls, tcount)

Outputs

int

Returns the same value as SPI_exec as well as

SPI_ERROR_ARGUMENT if plan is NULL or tcount < 0
SPI_ERROR_PARAM if values is NULL and plan was prepared with some parameters.

SPI_tuptable

initialized as in SPI_exec if successful

SPI_processed

initialized as in SPI_exec if successful

Usage

If nulls is NULL, then SPI_execp assumes that all values (if any) are not NULL.

Note

If one of the objects (a relation, function, etc.) referenced by the prepared plan is dropped during your session (by your backend or another process), then the results of SPI_execp for this plan will be unpredictable.