SPI_EXECUTE_PLAN(3)
π SPI_EXECUTE_PLAN(3) β bestie, let's run that prepared statement β¨
okay so real talk, this one lives in the PostgreSQL 16.15 docs, it's part of the SPI fam, and it's lowkey iconic. stay with me π«Ά
β¨ NAME β¨
SPI_execute_plan β bestie, this is literally the function that executes a statement you already prepared with SPI_prepare. no cap. π
πΈ SYNOPSIS πΈ
int SPI_execute_plan(SPIPlanPtr plan, Datum * values, const char * nulls,
bool read_only, long count)
π¦ DESCRIPTION π¦
so SPI_execute_plan executes a statement that was prepared by SPI_prepare or one of its siblings π. and the way that read_only and count work β they have the exact same interpretation as in SPI_execute. periodt, that's the whole vibe check. π
π ARGUMENTS π
SPIPlanPtr planβ the prepared statement (the one you got back fromSPI_prepare) πDatum * valuesβ an array of the actual parameter values. it must have the same length as the statement's number of arguments. don't skip, don't shrink, don't be cute about it π«Άconst char * nullsβ an array that says which of the params are null. same rule: it must have the same length as the statement's number of arguments.
so here's the tea π: if nulls is NULL, then SPI_execute_plan just assumes no parameters are null. otherwise, each entry of the nulls array should be ' ' if the matching parameter value is non-null, or 'n' if the matching parameter value is null. (and in that null case? the actual value sitting in the corresponding values entry genuinely doesn't matter, so like... don't stress π) also super important β nulls is not a text string, it's just an array, so it does not need a '\0' terminator. no trailing weirdness required β¨
bool read_onlyβtruefor read-only execution πlong countβ maximum number of rows to return, or0for no limit π₯
π RETURN VALUE π
the return value is the same as for SPI_execute, plus these extra possible error (negative) results β heads up bestie, negative means something went sideways π:
SPI_ERROR_ARGUMENTβ ifplanisNULLor invalid, orcountis less than0SPI_ERROR_PARAMβ ifvaluesisNULLandplanwas prepared with some parameters
and if it all slays successfully, SPI_processed and SPI_tuptable are set as in SPI_execute. β
ngl, the vibe here is: prepare once, execute many. but do your argument arrays right or the error codes will come for you π
okay that's the whole page, you ate it up fr fr π§π this iconic little number is from PostgreSQL 16.15, dated 2026, and it's SPI_EXECUTE_PLAN(3) β go forth and execute, bestie ππΈ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16-docs 16.15-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