バージョンごとのドキュメント一覧

SPI_execute_extended

SPI_execute_extended <refpurpose>execute a command with out-of-line parameters</refpurpose> — 行外のパラメータを持つコマンドを実行する

概要

int SPI_execute_extended(const char *command,
                         const SPIExecuteOptions * options)

説明

<title>Description</title>

<function>SPI_execute_extended</function> executes a command that might include references to externally supplied parameters. The command text refers to a parameter as <literal>$<replaceable>n</replaceable></literal>, and the <parameter>options-&gt;params</parameter> object (if supplied) provides values and type information for each such symbol. Various execution options can be specified in the <parameter>options</parameter> struct, too. SPI_execute_extendedは外部から供給されるパラメータへの参照を含むコマンドを実行します。 コマンドテキストはパラメータを$nとして参照し、options->paramsオブジェクトは(供給されれば)こうしたシンボル毎にデータ型と値を提供します。 様々な実行オプションをoptions構造体にも指定できます。

The <parameter>options-&gt;params</parameter> object should normally mark each parameter with the <literal>PARAM_FLAG_CONST</literal> flag, since a one-shot plan is always used for the query. その問い合わせに対しては一度限りの計画が必ず使われますので、options->paramsオブジェクトは通常各パラメータにPARAM_FLAG_CONSTフラグをつけるべきです。

If <parameter>options-&gt;dest</parameter> is not NULL, then result tuples are passed to that object as they are generated by the executor, instead of being accumulated in <varname>SPI_tuptable</varname>. Using a caller-supplied <literal>DestReceiver</literal> 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. options->destがNULLでなければ、結果タプルは、SPI_tuptableに蓄積される代わりに、エグゼキュータにより生成された時にそのオブジェクトに渡されます。 データがメモリに蓄積される代わりにその場で処理されるので、呼び出し元が提供するDestReceiverオブジェクトを使うことは、多数のタプルを生成する問い合わせに対して特に有用です。

引数

<title>Arguments</title>
const char * command

command string コマンド文字列

const SPIExecuteOptions * options

struct containing optional arguments オプションの引数を含む構造体

Callers should always zero out the entire <parameter>options</parameter> 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 <parameter>options</parameter> fields are: 呼び出し元は、必ずoptions構造体全体をゼロクリアしてから、設定したいフィールドを埋めるべきです。 構造体に将来追加されるフィールドは、ゼロであれば後方互換性があるように振る舞うよう定義されますので、これはコードの将来の互換性を確実にします。 現在利用可能なoptionsフィールドは以下の通りです。

ParamListInfo params

data structure containing query parameter types and values; NULL if none 問い合わせパラメータの型と値を含むデータ構造。なければNULL

bool read_only
<para><literal>true</literal> for read-only execution</para>

読み取りのみの実行の場合true

bool allow_nonatomic

<literal>true</literal> allows non-atomic execution of CALL and DO statements trueでCALLとDO文の非原子的実行を許可します

bool must_return_tuples

if <literal>true</literal>, 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) trueであれば、問い合わせがタプルを返す種類のものでない場合にエラーを発生します(これはたまたま0個のタプルを返す場合を禁止しません)

uint64 tcount

maximum number of rows to return, or <literal>0</literal> for no limit 返される行の最大数、無制限の場合には0

DestReceiver * dest

<literal>DestReceiver</literal> object that will receive any tuples emitted by the query; if NULL, result tuples are accumulated into a <varname>SPI_tuptable</varname> structure, as in <function>SPI_execute</function> 問い合わせが出すタプルを受け取るDestReceiverオブジェクト。 NULLなら、SPI_executeのように、結果タプルはSPI_tuptable構造体に蓄積されます。

ResourceOwner owner

This field is present for consistency with <function>SPI_execute_plan_extended</function>, but it is ignored, since the plan used by <function>SPI_execute_extended</function> is never saved. このフィールドはSPI_execute_plan_extendedとの一貫性のために存在しますが、無視されます。SPI_execute_extendedが使う計画は決して保存されないからです。

戻り値

<title>Return Value</title>

The return value is the same as for <function>SPI_execute</function>. 戻り値はSPI_executeと同じです。

When <parameter>options-&gt;dest</parameter> is NULL, <varname>SPI_processed</varname> and <varname>SPI_tuptable</varname> are set as in <function>SPI_execute</function>. When <parameter>options-&gt;dest</parameter> is not NULL, <varname>SPI_processed</varname> is set to zero and <varname>SPI_tuptable</varname> is set to NULL. If a tuple count is required, the caller's <literal>DestReceiver</literal> object must calculate it. options->destがNULLであれば、SPI_processedSPI_tuptableSPI_executeと同様に設定されます。 options->destがNULLでなければ、SPI_processedはゼロに設定され、SPI_tuptableはNULLに設定されます。 タプルの集計が必要なら、呼び出し元のDestReceiverオブジェクトが計算しなければなりません。