]> begriffs open source - ai-pg/blob - full-docs/html/contrib-dblink-fetch.html
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / html / contrib-dblink-fetch.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_fetch</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-open.html" title="dblink_open" /><link rel="next" href="contrib-dblink-close.html" title="dblink_close" /></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_fetch</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="contrib-dblink-open.html" title="dblink_open">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-close.html" title="dblink_close">Next</a></td></tr></table><hr /></div><div class="refentry" id="CONTRIB-DBLINK-FETCH"><div class="titlepage"></div><a id="id-1.11.7.21.13.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">dblink_fetch</span></h2><p>dblink_fetch — returns rows from an open cursor in a remote database</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 dblink_fetch(text cursorname, int howmany [, bool fail_on_error]) returns setof record
4 dblink_fetch(text connname, text cursorname, int howmany [, bool fail_on_error]) returns setof record
5 </pre></div><div class="refsect1" id="id-1.11.7.21.13.5"><h2>Description</h2><p>
6     <code class="function">dblink_fetch</code> fetches rows from a cursor previously
7     established by <code class="function">dblink_open</code>.
8    </p></div><div class="refsect1" id="id-1.11.7.21.13.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>
9        Name of the connection to use; omit this parameter to use the
10        unnamed connection.
11       </p></dd><dt><span class="term"><em class="parameter"><code>cursorname</code></em></span></dt><dd><p>
12        The name of the cursor to fetch from.
13       </p></dd><dt><span class="term"><em class="parameter"><code>howmany</code></em></span></dt><dd><p>
14        The maximum number of rows to retrieve. The next <em class="parameter"><code>howmany</code></em>
15        rows are fetched, starting at the current cursor position, moving
16        forward. Once the cursor has reached its end, no more rows are produced.
17       </p></dd><dt><span class="term"><em class="parameter"><code>fail_on_error</code></em></span></dt><dd><p>
18        If true (the default when omitted) then an error thrown on the
19        remote side of the connection causes an error to also be thrown
20        locally. If false, the remote error is locally reported as a NOTICE,
21        and the function returns no rows.
22       </p></dd></dl></div></div><div class="refsect1" id="id-1.11.7.21.13.7"><h2>Return Value</h2><p>
23     The function returns the row(s) fetched from the cursor.  To use this
24     function, you will need to specify the expected set of columns,
25     as previously discussed for <code class="function">dblink</code>.
26    </p></div><div class="refsect1" id="id-1.11.7.21.13.8"><h2>Notes</h2><p>
27     On a mismatch between the number of return columns specified in the
28     <code class="literal">FROM</code> clause, and the actual number of columns returned by the
29     remote cursor, an error will be thrown. In this event, the remote cursor
30     is still advanced by as many rows as it would have been if the error had
31     not occurred.  The same is true for any other error occurring in the local
32     query after the remote <code class="command">FETCH</code> has been done.
33    </p></div><div class="refsect1" id="id-1.11.7.21.13.9"><h2>Examples</h2><pre class="screen">
34 SELECT dblink_connect('dbname=postgres options=-csearch_path=');
35  dblink_connect
36 ----------------
37  OK
38 (1 row)
39
40 SELECT dblink_open('foo', 'select proname, prosrc from pg_proc where proname like ''bytea%''');
41  dblink_open
42 -------------
43  OK
44 (1 row)
45
46 SELECT * FROM dblink_fetch('foo', 5) AS (funcname name, source text);
47  funcname |  source
48 ----------+----------
49  byteacat | byteacat
50  byteacmp | byteacmp
51  byteaeq  | byteaeq
52  byteage  | byteage
53  byteagt  | byteagt
54 (5 rows)
55
56 SELECT * FROM dblink_fetch('foo', 5) AS (funcname name, source text);
57  funcname  |  source
58 -----------+-----------
59  byteain   | byteain
60  byteale   | byteale
61  bytealike | bytealike
62  bytealt   | bytealt
63  byteane   | byteane
64 (5 rows)
65
66 SELECT * FROM dblink_fetch('foo', 5) AS (funcname name, source text);
67   funcname  |   source
68 ------------+------------
69  byteanlike | byteanlike
70  byteaout   | byteaout
71 (2 rows)
72
73 SELECT * FROM dblink_fetch('foo', 5) AS (funcname name, source text);
74  funcname | source
75 ----------+--------
76 (0 rows)
77 </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-open.html" title="dblink_open">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-close.html" title="dblink_close">Next</a></td></tr><tr><td width="40%" align="left" valign="top">dblink_open </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_close</td></tr></table></div></body></html>