September 26, 2024: PostgreSQL 17 Released!
Supported Versions: Current (17) / 16 / 15 / 14 / 13 / 12
Development Versions: devel
Unsupported versions: 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

SPI_saveplan

Name

SPI_saveplan -- save a plan

Synopsis

SPIPlanPtr SPI_saveplan(SPIPlanPtr plan)

Description

SPI_saveplan saves a passed plan (prepared by SPI_prepare) in memory that will not be freed by SPI_finish nor by the transaction manager, and returns a pointer to the saved plan. This gives you the ability to reuse prepared plans in the subsequent invocations of your procedure in the current session.

Arguments

SPIPlanPtr plan

the plan to be saved

Return Value

Pointer to the saved plan; NULL if unsuccessful. On error, SPI_result is set thus:

SPI_ERROR_ARGUMENT

if plan is NULL or invalid

SPI_ERROR_UNCONNECTED

if called from an unconnected procedure

Notes

The passed-in plan is not freed, so you might wish to do SPI_freeplan on it to avoid leaking memory until SPI_finish.

If one of the objects (a table, function, etc.) referenced by the prepared plan is dropped or redefined, then future executions of SPI_execute_plan may fail or return different results than the plan initially indicates.