SPI_PREPARE_CURSOR(3)
π SPI_PREPARE_CURSOR π
okay bestie, so this one is SPI_PREPARE_CURSOR(3) from the PostgreSQL 18.6 docs, and it's literally the "get your statement ready but don't run it yet" girlie. she's giving preparation era, not execution era. π
β¨ NAME β¨
SPI_prepare_cursor β prepare a statement, without executing it yet
πΈ SYNOPSIS πΈ
SPIPlanPtr SPI_prepare_cursor(const char * command, int nargs,
Oid * argtypes, int cursorOptions)
π¦ DESCRIPTION π¦
so SPI_prepare_cursor is identical to SPI_prepare, except β and this is the moment, the plot twist β it also lets you specify the planner's "cursor options" parameter. π
that parameter is a bit mask, and the values you can put in it are the ones shown in nodes/parsenodes.h for the options field of DeclareCursorStmt. iykyk. meanwhile SPI_prepare is out here always taking the cursor options as zero, no options, no thoughts, head empty. π
heads up: this function is now deprecated in favor of SPI_prepare_extended. she's still here, she still works, but she's not the main character anymore. π«Ά
β ARGUMENTS β
const char * commandβ the command string. the actual SQL, the whole vibe, the script.int nargsβ number of input parameters, aka the$1,$2, etc. count them, bestie.Oid * argtypesβ a pointer to an array holding the OIDs of the data types of the parameters. it's giving "who are your parameters and what are they made of".int cursorOptionsβ integer bit mask of cursor options; zero produces default behavior. zero = no notes, just default. π
π RETURN VALUE π
SPI_prepare_cursor has the same return conventions as SPI_prepare. same energy, same rules, no surprises. β¨
π NOTES π
the 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 β like, in particular β that CURSOR_OPT_HOLD is ignored. she simply does not see it. don't count on it, fr fr. π
and that's the whole page, babe π this was PostgreSQL 18.6, dated 2026, and it's the SPI_PREPARE_CURSOR(3) manual page β go forth and prepare those cursors responsibly, mwah π«Άβ¨
π¦ 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