dblink_open <refpurpose>opens a cursor in a remote database</refpurpose> — リモートデータベースでカーソルを開く
dblink_open(text cursorname, text sql [, bool fail_on_error]) returns text dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) returns text
<function>dblink_open()</function> opens a cursor in a remote database.
The cursor can subsequently be manipulated with
<function>dblink_fetch()</function> and <function>dblink_close()</function>.
dblink_open()はリモートデータベースでカーソルを開きます。
その後カーソルをdblink_fetch()とdblink_close()で操作することができます。
connnameName of the connection to use; omit this parameter to use the unnamed connection. 使用する接続の名前です。 無名の接続を使用する場合はこのパラメータを省略します。
cursornameThe name to assign to this cursor. このカーソルに割り当てる名前です。
sql
The <command>SELECT</command> statement that you wish to execute in the remote
database, for example <literal>select * from pg_class</literal>.
例えばselect * from pg_classといった、リモートデータベースで実行させたいSELECT文です。
fail_on_error
If true (the default when omitted) then an error thrown on the
remote side of the connection causes an error to also be thrown
locally. If false, the remote error is locally reported as a NOTICE,
and the function's return value is set to <literal>ERROR</literal>.
真(省略時のデフォルト)の場合、接続のリモート側で発生したエラーによりローカル側でもエラーが発生します。
偽の場合リモート側のエラーはローカル側にはNOTICEとして報告され、この関数の戻り値はERRORになります。
Returns status, either <literal>OK</literal> or <literal>ERROR</literal>.
状態、つまりOKまたはERRORを返します。
Since a cursor can only persist within a transaction,
<function>dblink_open</function> starts an explicit transaction block
(<command>BEGIN</command>) on the remote side, if the remote side was
not already within a transaction. This transaction will be
closed again when the matching <function>dblink_close</function> is
executed. Note that if
you use <function>dblink_exec</function> to change data between
<function>dblink_open</function> and <function>dblink_close</function>,
and then an error occurs or you use <function>dblink_disconnect</function> before
<function>dblink_close</function>, your change <emphasis>will be
lost</emphasis> because the transaction will be aborted.
カーソルはトランザクション内でのみ持続することができますので、リモート側がまだトランザクションの内部でない場合、dblink_openはリモート側で明示的なトランザクションブロックを開始(BEGIN)します。
このトランザクションは対応するdblink_closeが実行された時に同様に閉ざされます。
dblink_openとdblink_closeの間にdblink_execを使用してデータを変更した場合、エラーが発生することに注意してください。
また、dblink_closeの前にdblink_disconnectを使用すると、トランザクションがアボートしますので変更が失われることに注意してください。
SELECT dblink_connect('dbname=postgres options=-csearch_path=');
dblink_connect
----------------
OK
(1 row)
SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
dblink_open
-------------
OK
(1 row)