DBLINK_EXEC(3)

πŸ“¦ version 14.24, in opensuse-leap 16.0

πŸ’– 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 for dblink_connect. yep, same energy. 🌸
  • sql β€” the SQL command that you wish to execute in the remote database, for example insert into foo values(0, 'a', '{"a0","b0","c0"}'). put it in the group chat. πŸ’Œ
  • fail_on_error β€” if true (the default when omitted), then an error thrown on the remote side of the connection causes an error to also be thrown locally. if false, the remote error is locally reported as a NOTICE, and the function's return value is set to ERROR. 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