DBLINK_GET_RESULT(3)
๐
DBLINK_GET_RESULT โ the dblink_get_result page, but make it make sense โจ
ok so bestie, you're in section 3 of the manual (that's the C library / function-call girlies, iykyk) and this page is all about dblink_get_result โ the function that scoops up the results of an async query you already yeeted over there earlier. ๐
๐ NAME ๐
dblink_get_result โ gets an async query result. that's it, that's the vibe. ๐ฆ
โจ SYNOPSIS โจ
dblink_get_result(text connname [, bool fail_on_error]) returns setof record
๐ DESCRIPTION ๐
okay so picture this: earlier you fired off a query with dblink_send_query and then justโฆ went about your business (main character energy, honestly). dblink_get_result is the function that comes back and collects the results of that asynchronous query. ๐
and if the query isn't done yet? she doesn't complain, she doesn't return half a result โ she just waits until it is. patient queen. โณ
๐ธ ARGUMENTS ๐ธ
connnameโ the name of the connection you're using. like, which bestie are we talking to rn. ๐fail_on_errorโ if this istrue(which is the default when you justโฆ omit it, love that for you), then an error thrown on the remote side of the connection makes an error get thrown locally too. matching energy fr fr. if it'sfalse, the remote error gets reported locally as aNOTICEinstead, and the function returns no rows. ๐ซถ
๐ RETURN VALUE ๐
okay so it depends on what kind of thing you sent over there, and there are two flavours:
- For an async query (that is, an SQL statement that returns rows), the function returns the row(s) that the query produced. โจ but โ to use this function you'll need to specify the expected set of columns, exactly as previously discussed for
dblink. no vibes-based column guessing, bestie. - For an async command (that is, an SQL statement that does not return rows), the function returns a single row with a single text column containing the command's status string. and yeah, it's still necessary to specify that the result will have a single text column in the calling
FROMclause. theFROMclause wants receipts. ๐งพ
๐ NOTES ๐
- this function must be called if
dblink_send_queryreturned1. non-negotiable. - 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. yes, one extra call. she needs closure before she'll move on. ๐ญ
- when you're using
dblink_send_queryanddblink_get_result,dblinkfetches 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, this can result in transient memory bloat in the local session. not the cute kind of bloat. ๐
ngl, it may be better to open a query like that as a cursor withdblink_openand then fetch a manageable number of rows at a time. alternatively, use plaindblink(), which avoids memory bloat by spooling large result sets to disk. ๐
๐ง EXAMPLES ๐ง
here's the whole saga, step by step. 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)
and then โ the extra call, the one that gets you the empty set result: ๐ซ
contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2 text, f3 text[]);
f1 | f2 | f3
----+----+----
(0 rows)
now let's send two statements in one go, because we're extra:
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? two result sets, two calls, then one more for the empty set. the math maths. ๐งฎโจ
๐ SEE ALSO ๐
no SEE ALSO on this page, bestie โ she stands alone. ๐
aaaand that's the whole page! ๐ซถ this manual came to you courtesy of PostgreSQL 15.19, dated 2026, filed under DBLINK_GET_RESULT(3) โ go forth and await your async results responsibly, icon. ๐๐
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql15-docs 15.19-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