dblink_get_result <refpurpose>gets an async query result</refpurpose> — 非同期問い合わせの結果を取得する
dblink_get_result(text connname [, bool fail_on_error]) returns setof record
    <function>dblink_get_result</function> collects the results of an
    asynchronous query previously sent with <function>dblink_send_query</function>.
    If the query is not already completed, <function>dblink_get_result</function>
    will wait until it is.
dblink_get_resultは、事前にdblink_send_queryで送信された非同期問い合わせの結果を収集します。
問い合わせがまだ完了していなかった場合、dblink_get_resultは終わるまで待機します。
   
connnameName of the connection to use. 使用する接続名です。
fail_on_errorIf 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 returns no rows. 真(省略時のデフォルト)の場合、接続のリモート側で発生したエラーによりローカル側でもエラーが発生します。 偽の場合リモート側のエラーはローカル側にはNOTICEとして報告され、この関数は行を返しません。
    For an async query (that is, an SQL statement returning rows),
    the function returns the row(s) produced by the query.  To use this
    function, you will need to specify the expected set of columns,
    as previously discussed for <function>dblink</function>.
非同期問い合わせ(行を返すSQL文の場合)について、この関数は問い合わせで生成された行を返します。
この関数を使用するためには、上のdblinkで説明したように想定する列集合を指定する必要があります。
   
    For an async command (that is, an SQL statement not returning rows),
    the function returns a single row with a single text column containing
    the command's status string.  It is still necessary to specify that
    the result will have a single text column in the calling <literal>FROM</literal>
    clause.
非同期コマンド(行を返さないSQL文の場合)について、この関数はコマンド状態文字列からなるテキスト列を1つ持つ1行を返します。
この場合も呼び出し元のFROM句で結果が単一のテキスト列を持つことを指定する必要があります。
   
    This function <emphasis>must</emphasis> be called if
    <function>dblink_send_query</function> returned 1.
    It must be called once for each query
    sent, and one additional time to obtain an empty set result,
    before the connection can be used again.
dblink_send_queryが1を返した場合にこの関数を呼び出さなければなりません。
接続を再度利用できるようになる前に、送信した問い合わせに対し一度呼び出されなければなりません。
もう一度実行すると空の結果集合を得ることになります。
   
    When using <function>dblink_send_query</function> and
    <function>dblink_get_result</function>, <application>dblink</application> fetches the entire
    remote query result before returning any of it to the local query
    processor.  If the query returns a large number of rows, this can result
    in transient memory bloat in the local session.  It may be better to open
    such a query as a cursor with <function>dblink_open</function> and then fetch a
    manageable number of rows at a time.  Alternatively, use plain
    <function>dblink()</function>, which avoids memory bloat by spooling large result
    sets to disk.
dblink_send_queryとdblink_get_resultを使う場合には、dblinkはリモート側の問い合わせ結果をローカルの問い合わせ処理に渡す前にすべて取り込みます。
問い合わせが大量の行を返す場合、ローカルセッションで一時的なメモリ膨張が起こるかも知れません。
そのような問い合わせはdblink_openでカーソルとして開き、それから一度に管理可能な行数を取り出す方が良いでしょう。
あるいは、普通のdblink()を使って下さい。
大きな結果集合をディスクにスプールすることでメモリ膨張を回避します。
   
contrib_regression=# SELECT dblink_connect('dtest1', 'dbname=contrib_regression');
 dblink_connect
----------------
 OK
(1 row)
contrib_regression=# SELECT * FROM
contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 < 3') AS t1;
 t1
----
  1
(1 row)
contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
 f1 | f2 |     f3
----+----+------------
  0 | a  | {a0,b0,c0}
  1 | b  | {a1,b1,c1}
  2 | c  | {a2,b2,c2}
(3 rows)
contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
 f1 | f2 | f3
----+----+----
(0 rows)
contrib_regression=# SELECT * FROM
contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 < 3; select * from foo where f1 > 6') AS t1;
 t1
----
  1
(1 row)
contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
 f1 | f2 |     f3
----+----+------------
  0 | a  | {a0,b0,c0}
  1 | b  | {a1,b1,c1}
  2 | c  | {a2,b2,c2}
(3 rows)
contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
 f1 | f2 |      f3
----+----+---------------
  7 | h  | {a7,b7,c7}
  8 | i  | {a8,b8,c8}
  9 | j  | {a9,b9,c9}
 10 | k  | {a10,b10,c10}
(4 rows)
contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
 f1 | f2 | f3
----+----+----
(0 rows)