SPI_EXECUTE_PLAN(3)

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

πŸ’… SPI_execute_plan β€” bestie edition

okay so this is the SPI_EXECUTE_PLAN(3) page from the PostgreSQL 14.24 docs, and we're about to make SPI_execute_plan make sense, fr fr. stay with me 🫢


✨ NAME ✨

SPI_execute_plan β€” it executes a statement that was prepared ahead of time by SPI_prepare. literally the "press play" button for a plan you already built 🎬


πŸŽ€ SYNOPSIS πŸŽ€

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

that's the whole signature, keep it exactly like that, no cap πŸ’…


🌸 DESCRIPTION 🌸

so SPI_execute_plan executes a statement that was prepared by SPI_prepare β€” or by one of its siblings, bestie, the whole family tree 🌳 read_only and count mean exactly the same thing they mean in SPI_execute, iykyk. same interpretation, same energy. ⭐


πŸ¦‹ ARGUMENTS πŸ¦‹

  • SPIPlanPtr plan β€” the prepared statement, aka the thing SPI_prepare handed you back. your main character. πŸ‘‘
  • Datum * values β€” an array of the actual parameter values. it must have the same length as the statement's number of arguments. same length or it's not gonna slay. πŸ“
  • const char * nulls β€” an array that describes which parameters are null. must also have the same length as the statement's number of arguments. πŸ“

so listen: if nulls is NULL, then SPI_execute_plan assumes no parameters are null. otherwise, each entry of the nulls array should be ' ' if the corresponding parameter value is non-null, or 'n' if the corresponding parameter value is null. (in that null case, the actual value sitting in the corresponding values entry doesn't matter at all β€” it could be anything, we don't care πŸ™ˆ.) and heads up: nulls is not a text string, it's just an array β€” it does not need a '\0' terminator. not me pointing that out because someone always gets confused 😭

  • bool read_only β€” true for read-only execution. that's it, that's the flag. πŸ”₯
  • long count β€” the maximum number of rows to return, or 0 for no limit. zero = unlimited, go off. 🌈

πŸ’– RETURN VALUE πŸ’–

the return value is the same as for SPI_execute, bestie β€” same deal, same vibes. but there are these extra possible error (negative) results you gotta know about:

  • 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. πŸ’€

SPI_processed and SPI_tuptable get set the same way as in SPI_execute, as long as it was successful. ✨


real talk: those two negative returns are the ones that'll sneak up on you. check your plan, check your values, check that count isn't negative. vibe check your arguments before you call, ok? 🧚

🌟 a lil sign-off 🌟

this page came from the PostgreSQL 14.24 documentation, dated 2026, and it's the SPI_EXECUTE_PLAN(3) manual page. that's the whole thing β€” you ate this, bestie, go prepare some plans πŸ’œ πŸŽ€

πŸ“¦ where this page comes from