DBLINK_EXEC(3)
π NAME π
okay bestie, welcome to DBLINK_EXEC(3) β the page for dblink_exec, which literally executes a command in a remote database. that's the whole vibe. π
β¨ SYNOPSIS β¨
three ways to call this icon, no cap:
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
π¦ DESCRIPTION π¦
so dblink_exec executes a command β and by βcommandβ we mean any SQL statement that doesn't return rows β in a remote database. iconic behavior, honestly. β¨
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, the first argument is treated as a connection info string as for dblink_connect, and the indicated connection is made just for the duration of this command. lowkey efficient. π«Ά
π ARGUMENTS π
connnameβ the name of the connection to use. omit this parameter and it uses the unnamed connection. simple as that. πconnstrβ a connection info string, as previously described fordblink_connect. yep, same energy. πΈsqlβ the SQL command that you wish to execute in the remote database, for exampleinsert into foo values(0, 'a', '{"a0","b0","c0"}'). put it in the group chat. π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. important, bestie. don't skip the fine print. π
π RETURN VALUE π
Returns status, either the command's status string or ERROR. that's it. that's the return. π
π₯ EXAMPLES π₯
here's the full glow-up, commands and output exactly as they are:
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)
xoxo, your Unix bestie π β this page is from PostgreSQL 14.24, dated 2026. periodt. π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14-docs 14.24-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