This page in other versions: 9.1 / 9.2 / 9.3 / 9.4 / current (9.5)  |  Development versions: devel  |  Unsupported versions: 7.4 / 8.0 / 8.1 / 8.2 / 8.3 / 8.4 / 9.0



SPI_connect -- connect a procedure to the SPI manager


int SPI_connect(void)


SPI_connect opens a connection from a procedure invocation to the SPI manager. You must call this function if you want to execute commands through SPI. Some utility SPI functions may be called from unconnected procedures.

If your procedure is already connected, SPI_connect will return the error code SPI_ERROR_CONNECT. This could happen if a procedure that has called SPI_connect directly calls another procedure that calls SPI_connect. While recursive calls to the SPI manager are permitted when an SQL command called through SPI invokes another function that uses SPI, directly nested calls to SPI_connect and SPI_finish are forbidden. (But see SPI_push and SPI_pop.)

Return Value


on success


on error


July 30, 2006, 3:01 p.m.

Apparently SPI_connect switches memory context (and switches back at SPI_finish). Do not call palloc while in this context if you want the data to be valid in the outer context.

Furthermore, if you call e.g. Float8GetDatum between SPI_connect and SPI_finish, the value represented by the Datum is subject to corruption after the call to SPI_finish. This is because Float8GetDatum pallocs space.

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