DBLINK_EXEC(3)

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

πŸŽ€ NAME πŸŽ€

dblink_exec β€” executes a command in a remote database. Yup bestie, this is the dblink_exec(3) manual page, and it's serving remote-SQL realness. πŸ’…

✨ 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

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so dblink_exec executes a command β€” that is, any SQL statement that doesn't return rows β€” in a remote database. It's giving "do the thing over there, report back" energy.

When two text arguments are given, the first one is first looked up as a persistent connection's name; if found, the command is executed on that connection. If 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. Literally just for this one command, then bye. πŸ’¨

πŸ’… ARGUMENTS πŸ’…

  • connname β€” Name of the connection to use; omit this parameter to use the unnamed connection.
  • connstr β€” A connection info string, as previously described for dblink_connect.
  • sql β€” The SQL command that you wish to execute in the remote database, for example insert into foo values(0, 'a', '{"a0","b0","c0"}').
  • 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.

🌈 RETURN VALUE 🌈

Returns status, either the command's status string or ERROR. That's it, that's the tea. 🍡

πŸ”₯ EXAMPLES πŸ”₯

Bestie, here's the whole example moment, copied exactly because we do not mess with literal commands:

       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)

Okay bestie, that's the whole dblink_exec(3) manual-page moment πŸ’œ This slay was brought to you by PostgreSQL 15.19, dated 2026 β€” go forth and execute remotely, mwah 🫢✨

πŸ“¦ where this page comes from