SPI_EXECUTE_PLAN(3)
π 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 thingSPI_preparehanded 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βtruefor read-only execution. that's it, that's the flag. π₯long countβ the maximum number of rows to return, or0for 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β ifplanisNULLor invalid, or ifcountis less than0. πSPI_ERROR_PARAMβ ifvaluesisNULLandplanwas 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 yourplan, check yourvalues, check thatcountisn'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
- opensuse-leap 16.0: postgresql14-docs 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms