SPI_SAVEPLAN(3)
β¨ SPI_SAVEPLAN(3) β¨
okay so bestie, welcome to the SPI_SAVEPLAN(3) page β straight out of the PostgreSQL 16.15 documentation, section 3 if you're keeping track π
. this one's about saving a prepared statement so it stays saved, and honestly? iconic behavior.
π NAME π
SPI_saveplan β save a prepared statement π«Ά
πΈ SYNOPSIS πΈ
SPIPlanPtr SPI_saveplan(SPIPlanPtr plan)
π¦ DESCRIPTION π¦
so what does it do? SPI_saveplan copies a statement you passed in (one that was prepared by SPI_prepare, obvs) into memory that will not be freed by SPI_finish and won't get freed by the transaction manager either π€. then it hands you back a pointer to the copied statement.
and likeβ¦ why do you care? bc this gives you the ability to reuse prepared statements in the subsequent invocations of your C function in the current session. that's the whole vibe. that's the point. β¨
π ARGUMENTS π
SPIPlanPtr planβ the prepared statement to be saved, your main character of the moment π
π₯ RETURN VALUE π₯
Pointer to the copied statement π β or NULL if unsuccessful π. on error, SPI_result gets set like this:
SPI_ERROR_ARGUMENTβ ifplanisNULLor invalid πSPI_ERROR_UNCONNECTEDβ if called from an unconnected C function π
π NOTES π
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. like, memory leaks are not the aesthetic bestie, pls handle it π«Ά
also, in most cases SPI_keepplan is preferred to this function β it accomplishes largely the same result without needing to physically copy the prepared statement's data structures. so maybe check that one out first? just saying π
and that's the whole page, no cap π β this was SPI_SAVEPLAN(3) from the PostgreSQL 16.15 documentation, dated 2026. go forth and save those plans, queen π§ββοΈβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16-docs 16.15-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