DBLINK_GET_RESULT(3)
π DBLINK_GET_RESULT(3) π
okay bestie, gather round, because we're talking about dblink_get_result from the PostgreSQL 18.6 Documentation and honestly? she's the finisher of the async dblink duo. no cap.
β¨ NAME β¨
dblink_get_result β gets an async query result π¦
β¨ SYNOPSIS β¨
dblink_get_result(text connname [, bool fail_on_error]) returns setof record
β¨ DESCRIPTION β¨
so basically dblink_get_result is the one who collects the results of an async query that you already sent off with dblink_send_query. she's the "i'll wait for you" bestie π
and if the query isn't done yet? she just waits. no drama, no error, she'll sit there until it's completed. patient queen. π
β¨ ARGUMENTS β¨
connnameβ the name of the connection you wanna use, periodt. πfail_on_errorβ if it'strue(which is the default when you just omit it entirely, iykyk), then any error thrown on the remote side of the connection makes an error get thrown locally too. if it'sfalse, the remote error gets reported locally as aNOTICEinstead, and the function just returns no rows. she's like "noted, moving on" π
β¨ RETURN VALUE β¨
okay so two vibes here, depending on what you sent:
async query β that's an SQL statement that returns rows. she gives you back the row(s) the query produced. to use this function you gotta specify the expected set of columns, exactly like we already talked about for dblink.
async command β that's an SQL statement that does not return rows. she gives you back a single row with a single text column containing the command's status string. and yes, you still have to specify that the result will have a single text column in the calling FROM clause. don't skip that part bestie, it's required. π
β¨ NOTES β¨
π¨ real talk: this function must be called ifdblink_send_queryreturned1. and it must be called once for each query sent, plus one additional time to obtain an empty set result, before the connection can be used again. yes, the extra one is mandatory. she's thorough like that. π
and here's the tea about memory: when you're using dblink_send_query and dblink_get_result together, dblink fetches the entire remote query result before returning any of it to the local query processor. so if the query returns a large number of rows, that can cause transient memory bloat in your local session. π
what's better? open that kind of query as a cursor with dblink_open and then fetch a manageable number of rows at a time. β¨ alternatively, just use plain dblink(), which avoids memory bloat by spooling large result sets to disk. pick your fighter, they're both valid. π«Ά
β¨ EXAMPLES β¨
here's the whole saga, verbatim, no edits, slay:
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)
see how she keeps calling until she hits that empty set? that's the "one additional time" thing. she's nothing if not consistent. π
okay that's the whole page bestie!! πΈ this came from the PostgreSQL 18.6 docs, dated 2026, and the manual page is DBLINK_GET_RESULT(3). go forth and async responsibly. π§β¨π
π¦ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 Β· PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 Β· PostgreSQL
- arch rolling: postgresql 18.6-4 Β· PostgreSQL
- fedora 43: postgresql-contrib 18.6-1.fc43 Β· PostgreSQL
- fedora 44: postgresql-contrib 18.6-1.fc44 Β· PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-doc-18 18.6-0ubuntu0.26.04.1 Β· PostgreSQL
- ubuntu stonking: postgresql-doc-18 18.6-3build2 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms