Postgresql 中文操作指南
SPI_execute_extended
SPI_execute_extended — 使用不在行中的参数执行命令
SPI_execute_extended — execute a command with out-of-line parameters
Description
SPI_execute_extended 执行一个命令,该命令可能包含对外部提供的参数的引用。命令文本将参数称为 $_n_ ,而 options→params 对象(如果提供)则为每个此类符号提供值和类型信息。还可以在 options 结构中指定各种执行选项。
SPI_execute_extended executes a command that might include references to externally supplied parameters. The command text refers to a parameter as $_n_, and the options→params object (if supplied) provides values and type information for each such symbol. Various execution options can be specified in the options struct, too.
由于总是针对查询使用一次性计划,因此 options→params 对象通常应使用 PARAM_FLAG_CONST 标志标记每个参数。
The options→params object should normally mark each parameter with the PARAM_FLAG_CONST flag, since a one-shot plan is always used for the query.
如果 options→dest 不是 NULL,则结果元组将作为执行器生成它们时传递给该对象,而不是累积在 SPI_tuptable 中。使用调用者提供的 DestReceiver 对象对于可能生成多个元组的查询特别有帮助,因为数据可以动态处理,而不是累积在内存中。
If options→dest is not NULL, then result tuples are passed to that object as they are generated by the executor, instead of being accumulated in SPI_tuptable. Using a caller-supplied DestReceiver object is particularly helpful for queries that might generate many tuples, since the data can be processed on-the-fly instead of being accumulated in memory.
Arguments
-
const char * _command_
-
command string
-
-
const SPIExecuteOptions * _options_
-
struct containing optional arguments
-
调用者应始终将整个 options 结构清零,然后填写任何他们想要设置的字段。这样可以确保代码的前向兼容性,因为将来添加到结构中的任何字段都被定义为在为零时向后兼容地工作。当前可用的 options 字段为:
Callers should always zero out the entire options struct, then fill whichever fields they want to set. This ensures forward compatibility of code, since any fields that are added to the struct in future will be defined to behave backwards-compatibly if they are zero. The currently available options fields are:
-
ParamListInfo _params_
-
data structure containing query parameter types and values; NULL if none
-
-
bool _read_only_
-
true for read-only execution
-
-
bool _allow_nonatomic_
-
true allows non-atomic execution of CALL and DO statements
-
-
bool _must_return_tuples_
-
if true, raise error if the query is not of a kind that returns tuples (this does not forbid the case where it happens to return zero tuples)
-
-
uint64 _tcount_
-
maximum number of rows to return, or 0 for no limit
-
-
DestReceiver * _dest_
-
DestReceiver object that will receive any tuples emitted by the query; if NULL, result tuples are accumulated into a SPI_tuptable structure, as in SPI_execute
-
-
ResourceOwner _owner_
-
This field is present for consistency with SPI_execute_plan_extended, but it is ignored, since the plan used by SPI_execute_extended is never saved.
-
Return Value
返回值与 SPI_execute 相同。
The return value is the same as for SPI_execute.
当 options→dest 为 NULL 时, SPI_processed 和 SPI_tuptable 被设定为 SPI_execute 中的值。当 options→dest 不为 NULL 时, SPI_processed 被设定为零而 SPI_tuptable 被设定为 NULL。如果需要元组数,则调用者的 DestReceiver 对象必须计算它。
When options→dest is NULL, SPI_processed and SPI_tuptable are set as in SPI_execute. When options→dest is not NULL, SPI_processed is set to zero and SPI_tuptable is set to NULL. If a tuple count is required, the caller’s DestReceiver object must calculate it.