DBLINK_EXEC(3)
π DBLINK_EXEC(3) β the PostgreSQL 17.11 glow-up
okay so bestie, buckle up, because this is dblink_exec from the PostgreSQL 17.11 Documentation and she is that girl. no preamble needed, let's go π«Ά
β¨ NAME β¨
dblink_exec β executes a command in a remote database π
π SYNOPSIS π
dblink_exec(text connname, text sql [, bool fail_on_error]) returns text
dblink_exec(text connstr, text sql [, bool fail_on_error]) returns text
dblink_exec(text sql [, bool fail_on_error]) returns text
like, three whole signatures. pick your fighter π
π¦ DESCRIPTION π¦
okay so dblink_exec executes a command in a remote database. and by "command" we mean any SQL statement that doesn't return rows β no rows coming back, she just goes and does the thing. periodt. β¨
and here's the vibe check on how it picks where to run: when you give it two text arguments, the first one is first looked up as a persistent connection's name. if it's found, the command is executed on that connection. if it's not found, then that first argument gets treated as a connection info string, just like for dblink_connect, and the indicated connection is made just for the duration of this command β like a little pop-up connection, here for a good time not a long time π§
π ARGUMENTS π
connnameβ the name of the connection to use. literally just omit this parameter if you wanna use the unnamed connection. no cap. πconnstrβ a connection info string, as previously described fordblink_connect. iykyk π₯sqlβ the SQL command that you wish to execute in the remote database, for exampleinsert into foo values(0, 'a', '{"a0","b0","c0"}'). yes bestie, that's the shape of it πfail_on_errorβ iftrue(and that's the default when omitted, queen of defaults π) 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. so like, you do still hear about it, she's just quieter about it π
β RETURN VALUE β
Returns status β either the command's status string or ERROR. that's it, that's the whole tea β
πΈ EXAMPLES πΈ
here's where she really ate, look at these:
SELECT dblink_connect('dbname=dblink_test_standby');
dblink_connect
----------------
OK
(1 row)
SELECT dblink_exec('insert into foo values(21, ''z'', ''{"a0","b0","c0"}'');');
dblink_exec
-----------------
INSERT 943366 1
(1 row)
SELECT dblink_connect('myconn', 'dbname=regression');
dblink_connect
----------------
OK
(1 row)
SELECT dblink_exec('myconn', 'insert into foo values(21, ''z'', ''{"a0","b0","c0"}'');');
dblink_exec
------------------
INSERT 6432584 1
(1 row)
SELECT dblink_exec('myconn', 'insert into pg_class values (''foo'')',false);
NOTICE: sql error
DETAIL: ERROR: null value in column "relnamespace" violates not-null constraint
dblink_exec
-------------
ERROR
(1 row)
see how the last one has false for fail_on_error? remote error shows up as a NOTICE with a DETAIL, and the return value is ERROR. she told you, she just didn't scream it ππ
real talk: that last example is the one to remember βfail_on_errorset tofalsemeans the remote error does not blow up locally, it gets reported as aNOTICEandERRORcomes back as the return value. lowkey iconic behavior π
π SEE ALSO π
hmm, this page doesn't give us a SEE ALSO section, so like... that's the whole page bestie, go forth and execute π¦
and that's the whole thing, mwah π β this was DBLINK_EXEC(3), signed off from PostgreSQL 17.11, dated 2026, and proud of it πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17-docs 17.11-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