Postgresql 中文操作指南
SPI_cursor_open
SPI_cursor_open——使用通过 SPI_prepare 创建的语句设置一个游标
SPI_cursor_open — set up a cursor using a statement created with SPI_prepare
Synopsis
Portal SPI_cursor_open(const char * name, SPIPlanPtr plan,
Datum * values, const char * nulls,
bool read_only)
Description
SPI_cursor_open 设置一个游标(在内部,一个门户)用于执行 SPI_prepare 准备的语句。这些参数与 SPI_execute_plan 的对应参数意义相同。
SPI_cursor_open sets up a cursor (internally, a portal) that will execute a statement prepared by SPI_prepare. The parameters have the same meanings as the corresponding parameters to SPI_execute_plan.
使用游标而不是直接执行语句有两个好处。首先,可以一次检索少量结果行,避免为返回多数行的查询导致内存溢出。其次,一个门户在当前 C 函数完成后仍然有效(实际上,它可以在当前事务结束时仍然有效)。将门户名称返回到 C 函数的调用者提供了一种以结果的方式返回一组行。
Using a cursor instead of executing the statement directly has two benefits. First, the result rows can be retrieved a few at a time, avoiding memory overrun for queries that return many rows. Second, a portal can outlive the current C function (it can, in fact, live to the end of the current transaction). Returning the portal name to the C function’s caller provides a way of returning a row set as result.
传入的参数数据将被复制到光标的门户中,因此可在光标仍然存在时释放它。
The passed-in parameter data will be copied into the cursor’s portal, so it can be freed while the cursor still exists.
Arguments
-
const char * _name_
-
name for portal, or NULL to let the system select a name
-
-
SPIPlanPtr _plan_
-
prepared statement (returned by SPI_prepare)
-
-
Datum * _values_
-
An array of actual parameter values. Must have same length as the statement’s number of arguments.
-
-
const char * _nulls_
-
An array describing which parameters are null. Must have same length as the statement’s number of arguments.
-
If nulls is NULL then SPI_cursor_open 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.
-
-
bool _read_only_
-
true for read-only execution
-