pg_select

Name

pg_select -- loop over the result of a SELECT statement -- SELECT 文の結果を繰り返し処理します。

Synopsis

pg_select dbHandle queryString
  arrayVar queryProcedure

入力

dbHandle

Specifies a valid database handle.

有効なデータベースハンドルを指定します。

queryString

Specifies a valid SQL select query.

有効な SQL select 問い合わせを指定します。

arrayVar

Array variable for tuples returned.

返されるタプル用の配列変数。

queryProcedure

Procedure run on each tuple found.

タプルが見つかる度に実行されるプロシージャ。

出力

resultHandle

the return result is either an error message or a handle for a query result.

戻される結果は、エラーメッセージまたは問い合わせ結果のハンドルの いずれかです。

説明

pg_select submits a SELECT query to the Postgres backend, and executes a given chunk of code for each tuple in the result. The queryString must be a SELECT statement. Anything else returns an error. The arrayVar variable is an array name used in the loop. For each tuple, arrayVar is filled in with the tuple field values, using the field names as the array indexes. Then the queryProcedure is executed.

pg_select は SELECT 問い合わせを Postgres バックエンドに送り、その結果内の 各タプルについて指定されたコード群を実行します。 queryString は SELECT 文でなければいけません。他の問い合わせはエラーを返します。変数 arrayVar は、ループ内で 使用される配列名です。各タプルについて arrayVar にはそのタプル のフィールド値がフィールド名でインデックスされた形で格納されます。そ して、queryProcedure が 実行されます。

使用方法

This would work if table "table" has fields "control" and "name" (and, perhaps, other fields):

下は "table" テーブルが "control" と "name" フィールド(と、その 他のフィールド)を持つ場合にうまく実行できます。

	pg_select $pgconn "SELECT * from table" array {
		puts [format "%5d %s" array(control) array(name)]
	}