]> begriffs open source - ai-pg/blob - full-docs/html/contrib-dblink-get-result.html
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / html / contrib-dblink-get-result.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>dblink_get_result</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="contrib-dblink-get-notify.html" title="dblink_get_notify" /><link rel="next" href="contrib-dblink-cancel-query.html" title="dblink_cancel_query" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">dblink_get_result</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="contrib-dblink-get-notify.html" title="dblink_get_notify">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="dblink.html" title="F.11. dblink — connect to other PostgreSQL databases">Up</a></td><th width="60%" align="center">F.11. dblink — connect to other PostgreSQL databases</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="contrib-dblink-cancel-query.html" title="dblink_cancel_query">Next</a></td></tr></table><hr /></div><div class="refentry" id="CONTRIB-DBLINK-GET-RESULT"><div class="titlepage"></div><a id="id-1.11.7.21.20.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">dblink_get_result</span></h2><p>dblink_get_result — gets an async query result</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 dblink_get_result(text connname [, bool fail_on_error]) returns setof record
4 </pre></div><div class="refsect1" id="id-1.11.7.21.20.5"><h2>Description</h2><p>
5     <code class="function">dblink_get_result</code> collects the results of an
6     asynchronous query previously sent with <code class="function">dblink_send_query</code>.
7     If the query is not already completed, <code class="function">dblink_get_result</code>
8     will wait until it is.
9    </p></div><div class="refsect1" id="id-1.11.7.21.20.6"><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>connname</code></em></span></dt><dd><p>
10        Name of the connection to use.
11       </p></dd><dt><span class="term"><em class="parameter"><code>fail_on_error</code></em></span></dt><dd><p>
12        If true (the default when omitted) then an error thrown on the
13        remote side of the connection causes an error to also be thrown
14        locally. If false, the remote error is locally reported as a NOTICE,
15        and the function returns no rows.
16       </p></dd></dl></div></div><div class="refsect1" id="id-1.11.7.21.20.7"><h2>Return Value</h2><p>
17     For an async query (that is, an SQL statement returning rows),
18     the function returns the row(s) produced by the query.  To use this
19     function, you will need to specify the expected set of columns,
20     as previously discussed for <code class="function">dblink</code>.
21    </p><p>
22     For an async command (that is, an SQL statement not returning rows),
23     the function returns a single row with a single text column containing
24     the command's status string.  It is still necessary to specify that
25     the result will have a single text column in the calling <code class="literal">FROM</code>
26     clause.
27    </p></div><div class="refsect1" id="id-1.11.7.21.20.8"><h2>Notes</h2><p>
28     This function <span class="emphasis"><em>must</em></span> be called if
29     <code class="function">dblink_send_query</code> returned 1.
30     It must be called once for each query
31     sent, and one additional time to obtain an empty set result,
32     before the connection can be used again.
33    </p><p>
34     When using <code class="function">dblink_send_query</code> and
35     <code class="function">dblink_get_result</code>, <span class="application">dblink</span> fetches the entire
36     remote query result before returning any of it to the local query
37     processor.  If the query returns a large number of rows, this can result
38     in transient memory bloat in the local session.  It may be better to open
39     such a query as a cursor with <code class="function">dblink_open</code> and then fetch a
40     manageable number of rows at a time.  Alternatively, use plain
41     <code class="function">dblink()</code>, which avoids memory bloat by spooling large result
42     sets to disk.
43    </p></div><div class="refsect1" id="id-1.11.7.21.20.9"><h2>Examples</h2><pre class="screen">
44 contrib_regression=# SELECT dblink_connect('dtest1', 'dbname=contrib_regression');
45  dblink_connect
46 ----------------
47  OK
48 (1 row)
49
50 contrib_regression=# SELECT * FROM
51 contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 &lt; 3') AS t1;
52  t1
53 ----
54   1
55 (1 row)
56
57 contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
58  f1 | f2 |     f3
59 ----+----+------------
60   0 | a  | {a0,b0,c0}
61   1 | b  | {a1,b1,c1}
62   2 | c  | {a2,b2,c2}
63 (3 rows)
64
65 contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
66  f1 | f2 | f3
67 ----+----+----
68 (0 rows)
69
70 contrib_regression=# SELECT * FROM
71 contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 &lt; 3; select * from foo where f1 &gt; 6') AS t1;
72  t1
73 ----
74   1
75 (1 row)
76
77 contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
78  f1 | f2 |     f3
79 ----+----+------------
80   0 | a  | {a0,b0,c0}
81   1 | b  | {a1,b1,c1}
82   2 | c  | {a2,b2,c2}
83 (3 rows)
84
85 contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
86  f1 | f2 |      f3
87 ----+----+---------------
88   7 | h  | {a7,b7,c7}
89   8 | i  | {a8,b8,c8}
90   9 | j  | {a9,b9,c9}
91  10 | k  | {a10,b10,c10}
92 (4 rows)
93
94 contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
95  f1 | f2 | f3
96 ----+----+----
97 (0 rows)
98 </pre></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="contrib-dblink-get-notify.html" title="dblink_get_notify">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="dblink.html" title="F.11. dblink — connect to other PostgreSQL databases">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="contrib-dblink-cancel-query.html" title="dblink_cancel_query">Next</a></td></tr><tr><td width="40%" align="left" valign="top">dblink_get_notify </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> dblink_cancel_query</td></tr></table></div></body></html>