SPI_SAVEPLAN(3)
π SPI_SAVEPLAN π
okay bestie, so this is a page from the PostgreSQL 17.11 Documentation set, and it's literally all about SPI_saveplan β a function that saves a prepared statement so it doesn't ghost you when the transaction ends. no cap, it's lowkey iconic for anyone writing C functions that need to reuse a plan across calls. π«Ά
β¨ NAME β¨
SPI_saveplan β save a prepared statement πΎ
π SYNOPSIS π
SPIPlanPtr SPI_saveplan(SPIPlanPtr plan)
πΈ DESCRIPTION πΈ
so SPI_saveplan copies a statement you pass in (one that was prepared by SPI_prepare, mmkay) into memory that will not be freed by SPI_finish nor by the transaction manager β and then it hands you back a pointer to that copied statement. the way this works is it literally gives you the ability to reuse prepared statements in the subsequent invocations of your C function in the current session. main character energy fr fr. β¨
π¦ ARGUMENTS π¦
SPIPlanPtr planβ the prepared statement that's getting saved, bestie. that's the one. π
π RETURN VALUE π
you get back a pointer to the copied statement π β¦ or NULL if it didn't work out π. on error, SPI_result gets set like this:
SPI_ERROR_ARGUMENTβ happens ifplanisNULLor invalid. yeah. not great. πSPI_ERROR_UNCONNECTEDβ happens if it's called from an unconnected C function. π
β NOTES β
the originally passed-in statement is not freed, so you might want to do SPI_freeplan on it to avoid leaking memory until SPI_finish. don't forget, okay? your memory will thank you. π§
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. so likeβ¦ consider it? π
and that's the whole vibe check, bestie π this page came to you courtesy of PostgreSQL 17.11, dated 2026 β go forth and save those plans responsibly πππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17-docs 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms