DBLINK_OPEN(3)
okay bestie, welcome to DBLINK_OPEN(3) β straight from the PostgreSQL 13.23 Documentation π this one is all about opening a cursor in a remote database, and yes itβs giving main-character database energy β¨
πΈ NAME πΈ
dblink_open β opens a cursor in a remote database π
β¨ SYNOPSIS β¨
dblink_open(text cursorname, text sql [, bool fail_on_error]) returns text
dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) returns text
π¦ DESCRIPTION π¦
dblink_open() opens a cursor in a remote database. Once itβs open, you can lowkey manipulate that cursor with dblink_fetch() and dblink_close() β iconic teamwork, no cap. π
π ARGUMENTS π
connnameβ the name of the connection to use. Omit this parameter to use the unnamed connection. π«Άcursornameβ the name to assign to this cursor.sqlβ theSELECTstatement you want to execute in the remote database, for exampleselect * from pg_class.fail_on_errorβ iftrue(the default when omitted), 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βs return value is set toERROR.
π₯ RETURN VALUE π₯
Returns status, either OK or ERROR. simple as that, bestie β¨
π NOTES π
okay so hereβs the tea: a cursor can only persist within a transaction, so dblink_open starts an explicit transaction block (BEGIN) on the remote side, if the remote side was not already within a transaction. This transaction will be closed again when the matching dblink_close is executed. π§
big warning, bestie: if you usedblink_execto change data betweendblink_openanddblink_close, and then an error occurs or you usedblink_disconnectbeforedblink_close, your change will be lost because the transaction will be aborted. π not dramatic, just true.
π EXAMPLES π
hereβs the whole vibe in action:
SELECT dblink_connect('dbname=postgres options=-csearch_path=');
dblink_connect
----------------
OK
(1 row)
SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
dblink_open
-------------
OK
(1 row)
thatβs the DBLINK_OPEN(3) moment β PostgreSQL 13.23, dated 2025. byeee bestie, go open those remote cursors responsibly ππ«Ά
π¦ 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