COPY コマンドに関連した関数

126) The COPY command in Postgres has options to read from or write to the network connection used by libpq. Therefore, functions are necessary to access this network connection directly so applications may take advantage of this capability.

Postgres の COPY コマンドでは, libpq が使っているネットワーク接続に対して読み込み, あるいは書き込みを選ぶことができるようになっています. そこでこのネットワーク接続に直接アクセスするための関数が必要になります. もちろんアプリケーションもこの機能によって恩恵を受けるでしょう.

127) These functions should be executed only after obtaining a PGRES_COPY_OUT or PGRES_COPY_IN result object from PQexec or PQgetResult.

これらの関数は,PQexec または PQgetResult から, PGRES_COPY_OUT か PGRES_COPY_IN 結果オブジェクトを受け取った後にのみ, 実行するべきです.

138) When using PQgetResult, the application should respond to a PGRES_COPY_OUT result by executing PQgetline repeatedly, followed by PQendcopy after the terminator line is seen. It should then return to the PQgetResult loop until PQgetResult returns NULL. Similarly a PGRES_COPY_IN result is processed by a series of PQputline calls followed by PQendcopy, then return to the PQgetResult loop. This arrangement will ensure that a copy in or copy out command embedded in a series of SQL commands will be executed correctly. Older applications are likely to submit a copy in or copy out via PQexec and assume that the transaction is done after PQendcopy. This will work correctly only if the copy in/out is the only SQL command in the query string.

PQgetResult を使うとき,アプリケーションは PQgetline を繰り返し呼び出して PGRES_COPY_OUT に応答し,最終行を見つけたら続いて PQendcopy を呼び出します. それから,PQgetResult が NULL を返すまで PQgetResult のループに戻っておくべきです. 同じように PGRES_COPY_IN は連続した PQputline で処理し, そして PQendcopy でしめくくった後に PQgetResult のループに戻ります. このようにすることで,ひとつづきの SQL コマンド群に含めたコピーイン/ アウトコマンドを確実に,また正しく実行できるはずです. 比較的古いアプリケーションでは,コピーイン/アウトを PQexec で実行し,PQendcopy の実行でトランザクションは完了する, と想定していることがよくあります. これは文字列中の SQL コマンドが唯一コピーイン/アウトであったときにのみ正しく動作します.