SPI_SAVEPLAN(3)

πŸ“¦ version 16.15, in opensuse-leap 16.0

✨ 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 β€” if plan is NULL or 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