1SPI_CURSOR_OPEN(3)       PostgreSQL 14.3 Documentation      SPI_CURSOR_OPEN(3)
2
3
4

NAME

6       SPI_cursor_open - set up a cursor using a statement created with
7       SPI_prepare
8

SYNOPSIS

10       Portal SPI_cursor_open(const char * name, SPIPlanPtr plan,
11                              Datum * values, const char * nulls,
12                              bool read_only)
13

DESCRIPTION

15       SPI_cursor_open sets up a cursor (internally, a portal) that will
16       execute a statement prepared by SPI_prepare. The parameters have the
17       same meanings as the corresponding parameters to SPI_execute_plan.
18
19       Using a cursor instead of executing the statement directly has two
20       benefits. First, the result rows can be retrieved a few at a time,
21       avoiding memory overrun for queries that return many rows. Second, a
22       portal can outlive the current C function (it can, in fact, live to the
23       end of the current transaction). Returning the portal name to the C
24       function's caller provides a way of returning a row set as result.
25
26       The passed-in parameter data will be copied into the cursor's portal,
27       so it can be freed while the cursor still exists.
28

ARGUMENTS

30       const char * name
31           name for portal, or NULL to let the system select a name
32
33       SPIPlanPtr plan
34           prepared statement (returned by SPI_prepare)
35
36       Datum * values
37           An array of actual parameter values. Must have same length as the
38           statement's number of arguments.
39
40       const char * nulls
41           An array describing which parameters are null. Must have same
42           length as the statement's number of arguments.
43
44           If nulls is NULL then SPI_cursor_open assumes that no parameters
45           are null. Otherwise, each entry of the nulls array should be ' ' if
46           the corresponding parameter value is non-null, or 'n' if the
47           corresponding parameter value is null. (In the latter case, the
48           actual value in the corresponding values entry doesn't matter.)
49           Note that nulls is not a text string, just an array: it does not
50           need a '\0' terminator.
51
52       bool read_only
53           true for read-only execution
54

RETURN VALUE

56       Pointer to portal containing the cursor. Note there is no error return
57       convention; any error will be reported via elog.
58
59
60
61PostgreSQL 14.3                      2022                   SPI_CURSOR_OPEN(3)
Impressum