1DBLINK_GET_RESULT(3)     PostgreSQL 11.6 Documentation    DBLINK_GET_RESULT(3)
2
3
4

NAME

6       dblink_get_result - gets an async query result
7

SYNOPSIS

9       dblink_get_result(text connname [, bool fail_on_error]) returns setof record
10

DESCRIPTION

12       dblink_get_result collects the results of an asynchronous query
13       previously sent with dblink_send_query. If the query is not already
14       completed, dblink_get_result will wait until it is.
15

ARGUMENTS

17       connname
18           Name of the connection to use.
19
20       fail_on_error
21           If true (the default when omitted) then an error thrown on the
22           remote side of the connection causes an error to also be thrown
23           locally. If false, the remote error is locally reported as a
24           NOTICE, and the function returns no rows.
25

RETURN VALUE

27       For an async query (that is, a SQL statement returning rows), the
28       function returns the row(s) produced by the query. To use this
29       function, you will need to specify the expected set of columns, as
30       previously discussed for dblink.
31
32       For an async command (that is, a SQL statement not returning rows), the
33       function returns a single row with a single text column containing the
34       command's status string. It is still necessary to specify that the
35       result will have a single text column in the calling FROM clause.
36

NOTES

38       This function must be called if dblink_send_query returned 1. It must
39       be called once for each query sent, and one additional time to obtain
40       an empty set result, before the connection can be used again.
41
42       When using dblink_send_query and dblink_get_result, dblink fetches the
43       entire remote query result before returning any of it to the local
44       query processor. If the query returns a large number of rows, this can
45       result in transient memory bloat in the local session. It may be better
46       to open such a query as a cursor with dblink_open and then fetch a
47       manageable number of rows at a time. Alternatively, use plain dblink(),
48       which avoids memory bloat by spooling large result sets to disk.
49

EXAMPLES

51           contrib_regression=# SELECT dblink_connect('dtest1', 'dbname=contrib_regression');
52            dblink_connect
53           ----------------
54            OK
55           (1 row)
56
57           contrib_regression=# SELECT * FROM
58           contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 < 3') AS t1;
59            t1
60           ----
61             1
62           (1 row)
63
64           contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
65            f1 | f2 |     f3
66           ----+----+------------
67             0 | a  | {a0,b0,c0}
68             1 | b  | {a1,b1,c1}
69             2 | c  | {a2,b2,c2}
70           (3 rows)
71
72           contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
73            f1 | f2 | f3
74           ----+----+----
75           (0 rows)
76
77           contrib_regression=# SELECT * FROM
78           contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 < 3; select * from foo where f1 > 6') AS t1;
79            t1
80           ----
81             1
82           (1 row)
83
84           contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
85            f1 | f2 |     f3
86           ----+----+------------
87             0 | a  | {a0,b0,c0}
88             1 | b  | {a1,b1,c1}
89             2 | c  | {a2,b2,c2}
90           (3 rows)
91
92           contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
93            f1 | f2 |      f3
94           ----+----+---------------
95             7 | h  | {a7,b7,c7}
96             8 | i  | {a8,b8,c8}
97             9 | j  | {a9,b9,c9}
98            10 | k  | {a10,b10,c10}
99           (4 rows)
100
101           contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
102            f1 | f2 | f3
103           ----+----+----
104           (0 rows)
105
106
107
108PostgreSQL 11.6                      2019                 DBLINK_GET_RESULT(3)
Impressum