DBLINK_GET_RESULT(3)
π dblink_get_result(3) β async result, bestie π
okay so this is the dblink_get_result(3) manual page, and it's literally about grabbing the result of an async query you already sent. no cap, it's giving βpatience is a virtueβ energy if the query isn't done yet. π¦
πΈ NAME πΈ
dblink_get_result β gets an async query result β¨
β¨ SYNOPSIS β¨
dblink_get_result(text connname [, bool fail_on_error]) returns setof record
π DESCRIPTION π
dblink_get_result collects the results of an asynchronous query that was previously sent with dblink_send_query. If the query is not already completed, dblink_get_result will wait until it is. π«Ά
π ARGUMENTS π
connnameβ the name of the connection to use. basically the connection's little name tag πfail_on_errorβ iftrue(and that's the default when you omit it), then an error thrown on the remote side of the connection causes an error to also be thrown locally. iffalse, the remote error is locally reported as aNOTICE, and the function returns no rows. π
π RETURN VALUE π
For an async query, meaning 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 dblink. π
For an async command, meaning 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 FROM clause. periodt. π
π«Ά NOTES π«Ά
This function must be called if dblink_send_query 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. like, the connection is not reusable until you do the whole ritual. π―οΈ
When using dblink_send_query and dblink_get_result, dblink 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 dblink_open and then fetch a manageable number of rows at a time. Alternatively, use plain dblink(), which avoids memory bloat by spooling large result sets to disk. πΎ
bestie, that memory bloat thing is real β if your result set is huge, don't just rawdog it withdblink_send_query+dblink_get_result. use a cursor or plaindblink(). π
π EXAMPLES π
here's the whole vibe, verbatim:
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)
xoxo, PostgreSQL 13.23 docs from 2025, page dblink_get_result(3) ππ«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13-docs 13.23-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms