DECLARE

Name

DECLARE  --  Defines a cursor for table access テーブルアクセス用のカーソルを定義する。

Synopsis

DECLARE cursor [ BINARY ] [ INSENSITIVE ] [ SCROLL ]
    CURSOR FOR query
    [ FOR { READ ONLY | UPDATE [ OF column [, ...] ] ]
  

入力

cursor

The name of the cursor to be used in subsequent FETCH operations..

この後に FETCH 操作などで使われる、カーソルの名前。

BINARY

Causes the cursor to fetch data in binary rather than in text format.

カーソルがテキスト形式ではなくバイナリ形式でデータを取り出す。

INSENSITIVE

SQL92 keyword indicating that data retrieved from the cursor should be unaffected by updates from other processes or cursors. Since cursor operations occur within transactions in Postgres this is always the case. This keyword has no effect.

カーソルから取り出されたデータが他のプロセスやカーソルによる 更新の影響を受けないことを示す、SQL92 の キーワード。Postgres でのカーソル 操作はトランザクションの内側で行なわれますので、常にこの状態 になっています。このキーワードは効果がありません。

SCROLL

SQL92 keyword indicating that data may be retrieved in multiple rows per FETCH operation. Since this is allowed at all times by Postgres this keyword has no effect.

1 つの FETCH 操作によって複数の行のデータを取り出すことがで きることを示す、SQL92 のキーワード。 Postgres では、常にこれは可能です ので、このキーワードは効果がありません。

query

An SQL query which will provide the rows to be governed by the cursor. Refer to the SELECT statement for further information about valid arguments.

カーソルによって管理される行を提供する、1 つの SQL 問い合わ せ。有効な引数に関するより詳細については SELECT 文を参照し て下さい。

READ ONLY

SQL92 keyword indicating that the cursor will be used in a readonly mode. Since this is the only cursor access mode available in Postgres this keyword has no effect.

読み取り専用モードでカーソルが使用されることを示す、 SQL92 のキーワード。これは Postgres における唯一のカーソルの アクセスモードですので、このキーワードは効果がありません。

UPDATE

SQL92 keyword indicating that the cursor will be used to update tables. Since cursor updates are not currently supported in Postgres this keyword provokes an informational error message.

カーソルがテーブルの更新に使用されることを示す、 SQL92 のキーワード。カーソルによる更新は今 のところ Postgres でサポートされて いませんので、このキーワードはこのことを伝えるエラーメッセー ジを表示します。

column

Column(s) to be updated. Since cursor updates are not currently supported in Postgres the UPDATE clause provokes an informational error message.

更新されるカラム(複数可)。カーソルによる更新は今のところ Postgres でサポートされていませ んので、UPDATE 句はこのことを伝えるエラーメッセージを表示 します。

出力

SELECT

The message returned if the SELECT is run successfully.

SELECT 文の実行が正常に終了した場合に返されるメッセージ。

NOTICE BlankPortalAssignName: portal "cursor" already exists

This error occurs if cursor is already declared.

このエラーは、引数 cursor が既に宣言 されていた場合に発生します。

ERROR: Named portals may only be used in begin/end transaction blocks

This error occurs if the cursor is not declared within a transaction block.

このエラーは、カーソルがトランザクションブロック内で宣言され なかった場合に発生します。

説明

DECLARE allows a user to create cursors, which can be used to retrieve a small number of rows at a time out of a larger query. Cursors can return data either in text or in binary foramt.

DECLARE によってユーザは、巨大な問い合わせの中 から一度に少数の行を取り出すことに使用できるカーソルを作成すること ができます。カーソルはテキストもしくはバイナリのどちらかの形式でデ ータを返すことができます。

Normal cursors return data in text format, either ASCII or another encoding scheme depending on how the Postgres backend was built. Since data is stored natively in binary format, the system must do a conversion to produce the text format. In addition, text formats are often larger in size than the corresponding binary format. Once the information comes back in text form, the client application may have to convert it to a binary format to manipulate it anyway.

カーソルは通常、ASCII または Postgres バックエンドがどのように構築されたのかに依存する ASCII 以外のコー ド化方式のどちらかのテキスト形式でデータを返します。データは固有の バイナリ形式で保存されていますので、システムはテキスト形式を生成す るために変換を行なう必要があります。更にテキスト形式の場合、対応す るバイナリ形式よりもそのサイズが大きくなることがよくあります。情報 がテキスト形式で返されると、クライアントアプリケーションはそれを何 とか取り扱うためにそれをバイナリ形式に変換する必要になることがあり ます。

BINARY cursors give you back the data in the native binary representation. So binary cursors will tend to be a little faster since they suffer less conversion overhead.

BINARY カーソルはデータをその固有のバイナリ表現で返します。バイナリ 形式のカーソルは変換のオーバヘッド分処理が少なくなりますので、多少 高速になる傾向があります。

As an example, if a query returns a value of one from an integer column, you would get a string of '1' with a default cursor whereas with a binary cursor you would get a 4-byte value equal to control-A ('^A').

例えば、問い合わせが整数カラムから 1 つの値を返す場合、デフォルト のカーソルでは '1' という文字列を入手することになりますが、バイナ リ形式のカーソルの場合は control-A ('^A')と同一の 4 バイトの値 を入手することになります。

Caution

BINARY cursors should be used carefully. User applications such as psql are not aware of binary cursors and expect data to come back in a text format.

BINARY カーソルは注意して使わなければなりません。 psql のようなユーザアプリケーションは バイナリ形式のカーソルと気づかずにデータはテキスト形式で返される ものとみなしています。

However, string representation is architecture-neutral whereas binary representation can differ between different machine architectures. Therefore, if your client machine and server machine use different representations (e.g. "big-endian" versus "little-endian"), you will probably not want your data returned in binary format.

しかし、文字列表現はアーキテクチャに中立ですが、バイナリ表現はマシ ンのアーキテクチャによって異なります。ですので、クライアントマシン とサーバマシンで異なる表現(例えば、"big-endian" 対 "little-endian" )を使用する場合、多分バイナリ形式でデータを戻そう とは考えないでしょう。

Tip: If you intend to display the data in ASCII, getting it back in ASCII will save you some effort on the client side.

データを ASCII で表示を行なう場合はデータを ASCII 形式で入手す ることでクライアント側での処理をいくつか省くことができます。

注意

Cursors are only available in transactions.

カーソルはトランザクション内部でのみ使用可能です。

Postgres does not have an explicit OPEN cursor statement; a cursor is considered to be open when it is declared.

Postgres には明示的な OPEN cursor 文がありません。カーソルは宣言され た段階で開かれたものとみなされます。

Note: In SQL92 cursors are only available in embedded applications. ecpg, the embedded SQL preprocessor for Postgres, supports the SQL92 conventions, including those involving DECLARE and OPEN statements.

SQL92 では、カーソルは埋め込みアプリケーショ ンでのみ使用可能です。Postgres にお ける埋め込み SQL プリプロセッサである ecpg は、これらDECLARE とOPEN 文を必 要とすることを含め、SQL92 規定をサポートして います。

使用法

To declare a cursor:

カーソルを宣言します。

DECLARE liahona CURSOR
    FOR SELECT * FROM films;
   

互換性

SQL92

SQL92 allows cursors only in embedded SQL and in modules. Postgres permits cursors to be used interactively. SQL92 allows embedded or modular cursors to update database information. All Postgres cursors are readonly. The BINARY keyword is a Postgres extension.

SQL92 では、カーソルを埋め込み SQL 内、及び、モジュール内でのみ使用できます。 Postgres では対話式にカーソルを使うこ とができます。SQL92 では、埋め込みまたはモジュ ール型のカーソルによってデータベースの情報を更新することができま す。全ての Postgres のカーソルは読み取 り専用です。BINARY キーワードは Postgres の拡張です。