SPI_SAVEPLAN(3)

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

πŸ’– SPI_SAVEPLAN(3) πŸ’–

okay so bestie, this is the SPI_saveplan page from the PostgreSQL 15.19 Documentation, and it's giving β€œsave your prepared statement so future-you can use it again” energy. No cap, let's get into it. πŸŽ€

✨ NAME ✨

SPI_saveplan β€” save a prepared statement. Literally the whole gig. πŸ’…

🌸 SYNOPSIS 🌸

SPIPlanPtr SPI_saveplan(SPIPlanPtr plan)

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so SPI_saveplan copies a statement you passed in β€” one that was prepared by SPI_prepare β€” into memory that will not be freed by SPI_finish nor by the transaction manager, and then it returns a pointer to the copied statement. The way this is lowkey iconic? It gives you the ability to reuse prepared statements in the subsequent invocations of your C function in the current session. Reuse era fr fr. ✨

πŸ’… ARGUMENTS πŸ’…

  • SPIPlanPtr plan β€” the prepared statement to be saved. That's the one, bestie. 🫢

πŸ”₯ RETURN VALUE πŸ”₯

A 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. Not valid? Not today. πŸ’€
  • SPI_ERROR_UNCONNECTED β€” if called from an unconnected C function. Ma'am, connect first. 😭

πŸ‘‘ 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. Memory leak vibes? We don't claim them. πŸ™ˆ
  • 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, check that one first, iykyk. πŸ’œ

and that's the whole page, bestie β€” cute sign-off time: this was from PostgreSQL 15.19, dated 2026. Mwah, go save those plans responsibly. πŸ§šβ€β™€οΈπŸ’–

πŸ“¦ where this page comes from