DBLINK_GET_RESULT(3)

๐Ÿ“ฆ version 15.19, in opensuse-leap 16.0

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 is true (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's false, the remote error gets reported locally as a NOTICE instead, 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 FROM clause. the FROM clause wants receipts. ๐Ÿงพ

๐Ÿ’€ NOTES ๐Ÿ’€

  • this function must be called if dblink_send_query returned 1. 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_query and dblink_get_result, 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, 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 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. ๐Ÿ“

๐Ÿงš 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