SPI_prepare

Name

SPI_prepare --  Connects your procedure to the SPI manager. ユーザ定義のプロシージャをSPIマネージャに接続します。

Synopsis

SPI_prepare(query, nargs, argtypes)

入力

query

Query string

問い合わせ文字列。

nargs

Number of input parameters ($1 ... $nargs - as in SQL-functions)

入力パラメータ( SQL 関数における $1 ... $nargs )の数。

argtypes

Pointer list of type OIDs to input arguments

入力引数を示す OID 型のポインタのリスト。

出力

void *

Pointer to an execution plan (parser+planner+optimizer)

実行計画(パーサ+プランナ+オブティマイザ)を示すポインタ。

Description

SPI_prepare creates and returns an execution plan (parser+planner+optimizer) but doesn't execute the query. Should only be called from a connected procedure.

SPI_prepare は、実行プラン(パーサ+プランナ+オブティマイザ)を生成し、それを返 します。問い合わせを実行しません。接続済みのプロシージャからのみ呼 び出して下さい。

使い方

nargs is number of parameters ($1 ... $nargs - as in SQL-functions), and nargs may be 0 only if there is not any $1 in query.

引数 nargs はパラメータ( SQL 関数の $1 ... $nargs )の数であり、 問い合わせに $1 が存在しない場合にのみ 0 となります。

Execution of prepared execution plans is sometimes much faster so this feature may be useful if the same query will be executed many times.

生成済み実行計画の実行は非常に高速な場合がありますので、同じ問い 合わせを何回も実行するような場合に、この機能は有益です。

The plan returned by SPI_prepare may be used only in current invocation of the procedure since SPI_finish frees memory allocated for a plan. See SPI_saveplan.

SPI_prepare で返される計画は、 SPI_finish がそれに割り当てたメモリ領域を開放しま すので、現在処理中のプロシージャ中でのみで使用できます。 SPI_saveplan を参照して下さい。

If successful, a non-null pointer will be returned. Otherwise, you'll get a NULL plan. In both cases SPI_result will be set like the value returned by SPI_exec, except that it is set to SPI_ERROR_ARGUMENT if query is NULL or nargs < 0 or nargs > 0 && argtypes is NULL.

成功した場合、非 NULL のポインタが返ります。失敗した時には NULL の プランが返ります。どちらにしても SPI_exec の戻り値同様、SPI_result が設定されます。ただし引数 query が NULL、または、nargs < 0、または、 nargs > 0 かつ 引数 argtypes が NULL の場合は SPI_ERROR_ARGUMENT が設定されます。