Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 977b9e43ddbf791a68788d984b14383d > files > 131

postgresql9.3-docs-9.3.9-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>dblink_get_result</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.3.9 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="dblink"
HREF="dblink.html"><LINK
REL="PREVIOUS"
TITLE="dblink_get_notify"
HREF="contrib-dblink-get-notify.html"><LINK
REL="NEXT"
TITLE="dblink_cancel_query"
HREF="contrib-dblink-cancel-query.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2015-06-13T20:07:22"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.3.9 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="dblink_get_notify"
HREF="contrib-dblink-get-notify.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="dblink.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="dblink_cancel_query"
HREF="contrib-dblink-cancel-query.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="CONTRIB-DBLINK-GET-RESULT"
></A
>dblink_get_result</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN151423"
></A
><H2
>Name</H2
>dblink_get_result&nbsp;--&nbsp;gets an async query result</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN151428"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>dblink_get_result(text connname [, bool fail_on_error]) returns setof record</PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN151430"
></A
><H2
>Description</H2
><P
>    <CODE
CLASS="FUNCTION"
>dblink_get_result</CODE
> collects the results of an
    asynchronous query previously sent with <CODE
CLASS="FUNCTION"
>dblink_send_query</CODE
>.
    If the query is not already completed, <CODE
CLASS="FUNCTION"
>dblink_get_result</CODE
>
    will wait until it is.
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN151436"
></A
><H2
>Arguments</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="PARAMETER"
>conname</TT
></DT
><DD
><P
>       Name of the connection to use.
      </P
></DD
><DT
><TT
CLASS="PARAMETER"
>fail_on_error</TT
></DT
><DD
><P
>       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 returns no rows.
      </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN151449"
></A
><H2
>Return Value</H2
><P
>    For an async query (that is, a 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 <CODE
CLASS="FUNCTION"
>dblink</CODE
>.
   </P
><P
>    For an async command (that is, a 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 <TT
CLASS="LITERAL"
>FROM</TT
>
    clause.
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN151455"
></A
><H2
>Notes</H2
><P
>    This function <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>must</I
></SPAN
> be called if
    <CODE
CLASS="FUNCTION"
>dblink_send_query</CODE
> 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.
   </P
><P
>    When using <CODE
CLASS="FUNCTION"
>dblink_send_query</CODE
> and
    <CODE
CLASS="FUNCTION"
>dblink_get_result</CODE
>, <SPAN
CLASS="APPLICATION"
>dblink</SPAN
> 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 <CODE
CLASS="FUNCTION"
>dblink_open</CODE
> and then fetch a
    manageable number of rows at a time.  Alternatively, use plain
    <CODE
CLASS="FUNCTION"
>dblink()</CODE
>, which avoids memory bloat by spooling large result
    sets to disk.
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN151466"
></A
><H2
>Examples</H2
><PRE
CLASS="SCREEN"
>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 &lt; 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 &lt; 3; select * from foo where f1 &gt; 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)</PRE
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="contrib-dblink-get-notify.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="contrib-dblink-cancel-query.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>dblink_get_notify</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="dblink.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>dblink_cancel_query</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>