Postgresql 中文操作指南
Description
SPI_saveplan 将传递的语句(由 SPI_prepare 准备)复制到不会由 SPI_finish 或事务管理器释放的内存中,并返回已复制语句的指针。这样,您便可以在当前会话中再次调用 C 函数时重新使用已准备的语句。
SPI_saveplan copies a passed statement (prepared by SPI_prepare) into memory that will not be freed by SPI_finish nor by the transaction manager, and returns a pointer to the copied statement. This gives you the ability to reuse prepared statements in the subsequent invocations of your C function in the current session.
Return Value
复制的语句的指针;如果失败,则为 NULL 。出现错误时,将 SPI_result 设置如下:
Pointer to the copied statement; or 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 C function
-
Notes
最初传递的语句不会释放,所以您可能希望对其执行 SPI_freeplan ,以便避免在 SPI_finish 之前泄露内存。
The originally passed-in statement is not freed, so you might wish to do SPI_freeplan on it to avoid leaking memory until SPI_finish.
在大多数情况下, SPI_keepplan 优于此函数,因为它实现了基本相同的结果,而无需实际复制已准备语句的数据结构。
In most cases, SPI_keepplan is preferred to this function, since it accomplishes largely the same result without needing to physically copy the prepared statement’s data structures.