SPI_CURS...WITH_ARGS(3)
β¨ SPI_cursor_open_with_args(3) β the PostgreSQL 18.6 glow-up β¨
okay bestie, sit down, hydrate, and let me tell you about SPI_cursor_open_with_args π this one lives in the PostgreSQL 18.6 docs and it's giving "set up a cursor using a query and parameters" energy, periodt.
πΈ NAME πΈ
SPI_cursor_open_with_args β set up a cursor using a query and parameters π
π¦ SYNOPSIS π¦
Portal SPI_cursor_open_with_args(const char *name,
const char *command,
int nargs, Oid *argtypes,
Datum *values, const char *nulls,
bool read_only, int cursorOptions)
like... look at that signature. iconic. no notes. π
π DESCRIPTION π
So what does it do, bestie? SPI_cursor_open_with_args sets up a cursor (internally, a portal) that will execute the specified query. That's the whole vibe. π₯
Most of the parameters have the same meanings as the corresponding parameters to SPI_prepare_cursor and SPI_cursor_open β so if you already know those, you're basically already fluent, iykyk. β¨
Now here's the tea β β for one-time query execution, this function should be preferred over SPI_prepare_cursor followed by SPI_cursor_open. But if the same command is going to be executed with many different parameters, either method might be faster, depending on the cost of re-planning versus the benefit of custom plans. it's giving "situationship with your query planner", honestly. π
The passed-in parameter data will be copied into the cursor's portal, so it can be freed while the cursor still exists. freeing your stuff early? self-care. π«Ά
β οΈ heads up bestie: this function is now deprecated in favor of SPI_cursor_parse_open, which provides equivalent functionality using a more modern API for handling query parameters. she's still here, she still works, but the new girl is the moment. π
π ARGUMENTS π
const char * nameβ name for portal, orNULLto let the system select a name. letting the system pick? delegating is a skill, honestly πconst char * commandβ command string πint nargsβ number of input parameters ($1,$2, etc.)Oid * argtypesβ an array of lengthnargs, containing the OIDs of the data types of the parameters π¦Datum * valuesβ an array of lengthnargs, containing the actual parameter values β¨const char * nullsβ an array of lengthnargs, describing which parameters are null.
If nulls is NULL then SPI_cursor_open_with_args assumes that no parameters are null. Otherwise, each entry of the nulls array should be ' ' if the corresponding parameter value is non-null, or 'n' if the corresponding parameter value is null. (In the latter case, the actual value in the corresponding values entry doesn't matter.) Note that nulls is not a text string, just an array: it does not need a '\0' terminator. not me being an array not a string, she's different like that π
bool read_onlyβtruefor read-only execution πint cursorOptionsβ integer bit mask of cursor options; zero produces default behavior. zero = default = unbothered, moisturized, in her own lane πΈ
β RETURN VALUE β
Pointer to portal containing the cursor. π
π¨ but listen: there is no error return convention; any error will be reported viaelog. so don't go checking for a NULL return like it's gonna tell you something, bestie. errors come throughelog, that's the whole system. π
and that's the page!! π
sending you the biggest vibes β this was PostgreSQL 18.6, dated 2026, and yes she's serving SPI_CURS...WITH_ARGS(3) energy from the very top to the very bottom. go forth and portal responsibly, bestie π¦β¨π
π¦ 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