SPI_CURSOR_PARSE_OPEN(3pg15)
okay bestie, you're on the SPI_CURSOR_PARSE_OPEN(3) page from the PostgreSQL 15.19 docs, and it's giving βset up a cursor using a query string and parametersβ energy π
β¨
π NAME π
SPI_cursor_parse_open β set up a cursor using a query string and parameters.
β¨ SYNOPSIS β¨
Portal SPI_cursor_parse_open(const char *name,
const char *command,
const SPIParseOpenOptions * options)
π DESCRIPTION π
okay so SPI_cursor_parse_open sets up a cursor (internally, a portal) that's gonna execute the query string you specify. no cap.
think of it as comparable to SPI_prepare_cursor followed by SPI_cursor_open_with_paramlist, except that parameter references within the query string are handled entirely by supplying a ParamListInfo object. iconic behavior, honestly.
if you're doing one-time query execution, this function should be preferred over SPI_prepare_cursor followed by SPI_cursor_open_with_paramlist. but if the same command is gonna run with many different parameters, either method might be faster β it depends on the cost of re-planning versus the benefit of custom plans. lowkey a tradeoff, iykyk.
normally, the options->params object should mark each parameter with the PARAM_FLAG_CONST flag, because a one-shot plan is always used for the query. periodt.
the parameter data you pass in gets copied into the cursor's portal, so you can free it while the cursor is still alive. cute and convenient π«Ά.
π«Ά ARGUMENTS π«Ά
okay bestie, here's the cast:
const char * nameβ name for portal, orNULLto let the system select a name.const char * commandβ command string.const SPIParseOpenOptions * optionsβ struct containing optional arguments.
callers should always zero out the entire options struct first, then fill whichever fields they want to set. that's what keeps code forward-compatible: any fields added to the struct in the future will be defined to behave backwards-compatibly if they're zero. it's giving βfuture-proof your faveβ β¨.
the currently available options fields are:
ParamListInfo paramsβ data structure containing query parameter types and values;NULLif none.int cursorOptionsβ integer bit mask of cursor options; zero produces default behavior.bool read_onlyβtruefor read-only execution.
π RETURN VALUE π
you get back a pointer to the portal containing the cursor. heads up: there is no error return convention; any error will be reported via elog. so yeah, no sneaky error-return situation here π.
β with love, PostgreSQL 15.19 Β· 2026 Β· SPI_CURSOR_PARSE_OPEN(3) ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15-docs 15.19-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