]> begriffs open source - ai-pg/blob - full-docs/txt/spi-spi-cursor-open.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / spi-spi-cursor-open.txt
1
2 SPI_cursor_open
3
4    SPI_cursor_open — set up a cursor using a statement created with
5    SPI_prepare
6
7 Synopsis
8
9 Portal SPI_cursor_open(const char * name, SPIPlanPtr plan,
10                        Datum * values, const char * nulls,
11                        bool read_only)
12
13 Description
14
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
29 Arguments
30
31    const char * name
32           name for portal, or NULL to let the system select a name
33
34    SPIPlanPtr plan
35           prepared statement (returned by SPI_prepare)
36
37    Datum * values
38           An array of actual parameter values. Must have same length as
39           the statement's number of arguments.
40
41    const char * nulls
42           An array describing which parameters are null. Must have same
43           length as the statement's number of arguments.
44
45           If nulls is NULL then SPI_cursor_open assumes that no parameters
46           are null. Otherwise, each entry of the nulls array should be ' '
47           if the corresponding parameter value is non-null, or 'n' if the
48           corresponding parameter value is null. (In the latter case, the
49           actual value in the corresponding values entry doesn't matter.)
50           Note that nulls is not a text string, just an array: it does not
51           need a '\0' terminator.
52
53    bool read_only
54           true for read-only execution
55
56 Return Value
57
58    Pointer to portal containing the cursor. Note there is no error return
59    convention; any error will be reported via elog.