SPI_EXEC..._EXTENDED(3)
π SPI_EXECUTE_PLAN_EXTENDED π
okay bestie, gather round, because we're about to talk about SPI_execute_plan_extended from the PostgreSQL 18.6 docs, and honestly? it's giving β¨main character energyβ¨ for anyone writing C extensions. π¦
β¨ NAME β¨
SPI_execute_plan_extended β execute a statement prepared by SPI_prepare π
β¨ SYNOPSIS β¨
int SPI_execute_plan_extended(SPIPlanPtr plan,
const SPIExecuteOptions * options)
β¨ DESCRIPTION β¨
so SPI_execute_plan_extended runs a statement that was prepared by SPI_prepare or one of its siblings. πΈ
It's basically SPI_execute_plan's cooler twin β same energy, but the info about the parameter values you're passing to the query gets presented differently, and you also get extra execution-controlling options to play with. π
Your query parameter values are represented by a ParamListInfo struct, which is lowkey so convenient when you've already got values chillin' in that exact format. And dynamic parameter sets? Also a thing! Via hook functions specified in ParamListInfo. πͺ
AND, the best part, ngl: instead of always accumulating the result tuples into a SPI_tuptable structure, you can hand tuples off to a caller-supplied DestReceiver object as the executor generates them. This is iconic for queries that might generate a LOT of tuples, because the data gets processed on-the-fly instead of being accumulated in memory. π§ π
β¨ ARGUMENTS β¨
SPIPlanPtr planβ the prepared statement (returned bySPI_prepare) π«Άconst SPIExecuteOptions * optionsβ struct containing optional arguments
β οΈ okay important one bestie: callers should always zero out the entire options struct, then fill whichever fields they want to set. This ensures forward compatibility of your code, since any fields added to the struct in future will be defined to behave backwards-compatibly if they are zero. no cap. π
The currently available options fields are:
ParamListInfo paramsβ data structure containing query parameter types and values;NULLif nonebool read_onlyβtruefor read-only executionbool allow_nonatomicβtrueallows non-atomic execution ofCALLandDOstatements (but this field is ignored unless theSPI_OPT_NONATOMICflag was passed toSPI_connect_ext) π¨bool must_return_tuplesβ iftrue, raise error if the query is not of a kind that returns tuples (this does not forbid the case where it happens to return zero tuples)uint64 tcountβ maximum number of rows to return, or0for no limitDestReceiver * destβDestReceiverobject that will receive any tuples emitted by the query; ifNULL, result tuples are accumulated into aSPI_tuptablestructure, as inSPI_execute_planResourceOwner ownerβ The resource owner that will hold a reference count on the plan while it is executed. IfNULL,CurrentResourceOwneris used. Ignored for non-saved plans, as SPI does not acquire reference counts on those.
β¨ RETURN VALUE β¨
The return value is the same as for SPI_execute_plan. simple as that. π
When options->dest is NULL, SPI_processed and SPI_tuptable are set as in SPI_execute_plan. π·
When options->dest is not NULL, SPI_processed is set to zero and SPI_tuptable is set to NULL. So if a tuple count is required, the caller's DestReceiver object must calculate it. π (not me making you do your own math tho π)
and that's the whole page, bestie!! π this was PostgreSQL 18.6 documentation, dated 2026, and you absolutely ate that read. go forth and prepare those statements. slay. π β¨π
π¦ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 Β· PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 Β· PostgreSQL
- arch rolling: postgresql 18.6-4 Β· PostgreSQL
- fedora 43: postgresql-server-devel 18.6-1.fc43 Β· PostgreSQL
- fedora 43: postgresql-server-devel 18.6-1.fc43 Β· PostgreSQL
- fedora 44: postgresql-server-devel 18.6-1.fc44 Β· PostgreSQL
- fedora 44: postgresql-server-devel 18.6-1.fc44 Β· PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-doc-18 18.6-0ubuntu0.26.04.1 Β· PostgreSQL
- ubuntu stonking: postgresql-doc-18 18.6-3build2 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms