SPI_EXECUTE_PLAN(3)

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

✨ SPI_EXECUTE_PLAN ✨

okay so bestie, this is the SPI_EXECUTE_PLAN(3) page from the PostgreSQL 17.11 docs, and we're literally about to make prepared-statement execution make Sense πŸ’… buckle up.


πŸŽ€ NAME πŸŽ€

SPI_execute_plan β€” the one that runs a statement you already prepped with SPI_prepare. it's giving "reusing your fave fit instead of building a new one" πŸ‘‘


🌸 SYNOPSIS 🌸

int SPI_execute_plan(SPIPlanPtr plan, Datum * values, const char * nulls,
                     bool read_only, long count)

five args, no cap. count them. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

k so SPI_execute_plan executes a statement that was prepared by SPI_prepare or one of its siblings (yes, it has siblings, it's a whole family situation πŸ‘―). the read_only and count params mean exactly the same thing they mean in SPI_execute β€” same interpretation, no plot twist, no extra lore. periodt. ⭐


πŸ’– ARGUMENTS πŸ’–

  • SPIPlanPtr plan β€” your prepared statement, aka the thing SPI_prepare handed you back. main character energy right here πŸ‘‘
  • Datum * values β€” an array of the actual parameter values. it must be the same length as the statement's number of arguments β€” no short-changing, no extras, it's a vibe check and it has to match πŸ’€
  • const char * nulls β€” an array that says which parameters are null. also must be the same length as the statement's number of arguments.

here's the tea β˜• if nulls is NULL, then SPI_execute_plan assumes no parameters are null. otherwise, each entry of the nulls array should be ' ' when the matching parameter value is non-null, or 'n' when the matching parameter value is null. (and in that null case, whatever you stuffed in the corresponding values entry literally doesn't matter β€” it's irrelevant, it's not the moment πŸ™ˆ.) also important: nulls is not a text string, it's just an array β€” so it does not need a '\0' terminator, bestie, don't add one πŸŽ€

  • bool read_only β€” pass true for read-only execution. simple as that ✨
  • long count β€” maximum number of rows to return, or 0 for no limit. zero means "all of them, idc, bring the whole menu" πŸ“

πŸ”₯ RETURN VALUE πŸ”₯

the return value is the same as for SPI_execute β€” same deal, same energy β€” with these additional possible error (negative) results:

  • SPI_ERROR_ARGUMENT β€” if plan is NULL or invalid, or if count is less than 0 😭
  • SPI_ERROR_PARAM β€” if values is NULL and plan was prepared with some parameters

and if it all goes well, SPI_processed and SPI_tuptable are set just like in SPI_execute πŸŒˆπŸ’œ


ngl, if you're getting negative returns, check your plan first. it's almost always the plan. 🧚

okay that's the whole page, you ate it up fr fr 🫢 this was SPI_EXECUTE_PLAN(3) from the PostgreSQL 17.11 Documentation, dated 2026 β€” go forth and execute your plans, icon πŸ’…πŸ‘‘

πŸ“¦ where this page comes from