SPI_EXECUTE_EXTENDED(3)
β¨ NAME β¨
SPI_execute_extended β bestie, it runs a command, but the parameters come from outside the command text π
πΈ SYNOPSIS πΈ
int SPI_execute_extended(const char *command,
const SPIExecuteOptions * options)
π¦ DESCRIPTION π¦
okay so SPI_execute_extended executes a command that might include references to externally supplied parameters. The command text points at a parameter by writing $n, and the options->params object (if you actually pass one) hands over the values and the type info for each of those lil $n symbols. You can also stack a bunch of other execution options into the options struct, so like, it's a whole vibe buffet β¨
The options->params object should normally mark each parameter with the PARAM_FLAG_CONST flag, because a one-shot plan is always used for the query. no cap, always. π«Ά
And if options->dest is not NULL? Then result tuples get passed straight to that object as the executor generates them, instead of being accumulated into SPI_tuptable. Using a caller-supplied DestReceiver object is particularly helpful for queries that might generate many tuples, since the data can be processed on-the-fly instead of piling up in memory. it's giving efficiency, it's giving main character energy π₯
π ARGUMENTS π
const char * commandβ the command string, literally the thing you want run πconst SPIExecuteOptions * optionsβ a struct containing optional arguments, aka the little bag of settings
π¨ IMPORTANT BESTIE ALERT π¨ Callers should always zero out the entire options struct, and then fill in whichever fields they want to set. This is how you keep your code forward compatible β any fields that get added to the struct in the future will be defined to behave backwards-compatibly if they are zero. so zero it first, fr fr. don't skip this. π
the currently available options fields areβ¦ π
ParamListInfo paramsβ data structure containing query parameter types and values;NULLif none βbool read_onlyβtruefor read-only execution πbool allow_nonatomicβtrueallows non-atomic execution ofCALLandDOstatements (but heads up, 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 (and to be clear, this does not forbid the case where it happens to return zero tuples β zero tuples is still a valid tuple-returning query, okurrr) πuint64 tcountβ maximum number of rows to return, or0for no limit πDestReceiver * destβ DestReceiver object that will receive any tuples emitted by the query; ifNULL, result tuples are accumulated into aSPI_tuptablestructure, as inSPI_executeπResourceOwner ownerβ This field is present for consistency withSPI_execute_plan_extended, but it is ignored, since the plan used bySPI_execute_extendedis never saved. it's literally just there for the vibes β¨
π RETURN VALUE π
The return value is the same as for SPI_execute. (yes, that's the whole tea β)
When options->dest is NULL, SPI_processed and SPI_tuptable are set as in SPI_execute. πΈ
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. that's on you bestie, the function is not doing it for you π
π
and that's the whole page!! brought to you by PostgreSQL 18.6, documented back in 2026 β mwah, love that for us π«Άβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql18-docs 18.6-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms