SPI_KEEPPLAN(3)

πŸ’– SPI_KEEPPLAN(3) πŸ’–

okay bestie, welcome to the SPI_keepplan page, straight out of the PostgreSQL 18.6 Documentation ✨ this one's a lil C-level gem, and honestly? it's giving forever-statement energy πŸ’…


🌸 NAME 🌸

SPI_keepplan β€” save a prepared statement 🫢


✨ SYNOPSIS ✨

int SPI_keepplan(SPIPlanPtr plan)

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, bestie β˜• SPI_keepplan saves a passed statement β€” one that was prepared by SPI_prepare β€” so that it will not be freed by SPI_finish nor by the transaction manager. 😀 like, it's protected. it's safe. it's untouchable.

and why do we care?? because this gives you the ability to reuse prepared statements in the subsequent invocations of your C function in the current session. πŸŽ€ it's literally the "keep it for later" button and the way that it just... persists?? obsessed. ✨


πŸ’… ARGUMENTS πŸ’…

  • SPIPlanPtr plan β€” the prepared statement to be saved πŸ₯° that's it, that's the whole argument, she's simple and she slays

πŸ‘‘ RETURN VALUE πŸ‘‘

  • 0 on success πŸŽ‰ yay!
  • SPI_ERROR_ARGUMENT if plan is NULL or invalid πŸ’€ yeah no, that one's not cute

🌈 NOTES 🌈

ngl this part is kinda iconic πŸ”₯ the passed-in statement is relocated to permanent storage by means of pointer adjustment β€” and no data copying is required. zero copying. none. the pointer just... moves. main character energy fr fr πŸ’«

and if you later wish to delete it, use SPI_freeplan on it 🧹 because everything that stays forever eventually needs a lil cleanup, iykyk

and that's the whole page, bestie!! 🌸 this was PostgreSQL 18.6, dated 2026, and you just read the SPI_KEEPPLAN(3) manual page πŸ’– go keep those plans, periodt πŸ’…βœ¨