Table of Contents
SPI_prepareSPI_preparetrue if a statement prepared bySPI_prepare can be used withSPI_cursor_openSPI_prepareSPI_prepareSPI_prepareSPI_prepareSPI_execute or a similar functionTheServer Programming Interface (SPI) gives writers of user-definedC functions the ability to runSQL commands inside their functions or procedures.SPI is a set of interface functions to simplify access to the parser, planner, and executor.SPI also does some memory management.
The available procedural languages provide various means to execute SQL commands from functions. Most of these facilities are based on SPI, so this documentation might be of use for users of those languages as well.
Note that if a command invoked via SPI fails, then control will not be returned to your C function. Rather, the transaction or subtransaction in which your C function executes will be rolled back. (This might seem surprising given that the SPI functions mostly have documented error-return conventions. Those conventions only apply for errors detected within the SPI functions themselves, however.) It is possible to recover control after an error by establishing your own subtransaction surrounding SPI calls that might fail.
Source code files that use SPI must include the header fileexecutor/spi.h.