SPI_finish -- Disconnects your procedure from the SPI manager.
if properly disconnected
if called from an un-connected procedure
SPI_finish closes an existing connection to the
You must call this function after completing the SPI operations needed
during your procedure's current invocation.
You may get the error return SPI_ERROR_UNCONNECTED if SPI_finish is
called without having a current valid connection.
There is no fundamental problem
with this; it means that nothing was done by the SPI manager.
SPI_finishmust be called as a final step by a connected procedure,
or you may get
unpredictable results! However, you do not need to worry about making
this happen if the transaction is aborted via elog(ERROR). In that case
SPI will clean itself up.
SPI_finish performs the following:
Disconnects your procedure from the SPI manager and frees all memory
allocations made by your procedure via palloc since
These allocations can't be used any more! See Memory management.