SPI_PREPARE_CURSOR(3)
โจ SPI_prepare_cursor(3) โจ
Okay bestie, gather round ๐ this page is literally about preparing a statement and not executing it yet. Itโs giving โprep now, run laterโ energy. No cap.
๐ NAME ๐
SPI_prepare_cursor โ prepare a statement, without executing it yet. Thatโs the whole vibe: prep the statement, do not run it yet, periodt.
โจ SYNOPSIS โจ
SPIPlanPtr SPI_prepare_cursor(const char * command, int nargs,
Oid * argtypes, int cursorOptions)
๐ DESCRIPTION ๐
SPI_prepare_cursor is identical to SPI_prepare, except it also lets you specify the plannerโs โcursor optionsโ parameter. Yes, thatโs the extra little sparkle โจ.
That parameter is a bit mask, and its values are the ones shown in nodes/parsenodes.h for the options field of DeclareCursorStmt. Meanwhile, SPI_prepare always takes the cursor options as zero โ no options, just zero, default behavior.
๐จ Important: this function is now deprecated in favor ofSPI_prepare_extended. Like, itโs still a thing, but itโs not the main character anymore. ChooseSPI_prepare_extendedif youโre starting fresh. ๐
๐ฆ ARGUMENTS ๐ฆ
const char * commandโ the command string. Itโs a string, bestie.int nargsโ number of input parameters ($1,$2, etc.). Count them, donโt guess.Oid * argtypesโ pointer to an array containing the OIDs of the data types of the parameters. Itโs a pointer, it points at the OID array, you got this.int cursorOptionsโ integer bit mask of cursor options; zero produces default behavior. Zero = default. Simple as that.
๐ RETURN VALUE ๐
SPI_prepare_cursor has the same return conventions as SPI_prepare. So if you know how SPI_prepare returns, thatโs the exact same deal here. No new drama.
๐ NOTES ๐
Useful bits to set in cursorOptions include:
CURSOR_OPT_SCROLLCURSOR_OPT_NO_SCROLLCURSOR_OPT_FAST_PLANCURSOR_OPT_GENERIC_PLANCURSOR_OPT_CUSTOM_PLAN
And note in particular that CURSOR_OPT_HOLD is ignored. Not โhandled differently,โ not โextra specialโ โ ignored. So donโt come for CURSOR_OPT_HOLD, okay? ๐
Signed, sealed, and slayed by PostgreSQL 14.24 Documentation, dated 2026. Thatโs the source/version and date, bestie, right at the bottom where it belongs. ๐ซถ
๐ฆ 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