1DBLINK_EXEC(3) PostgreSQL 13.3 Documentation DBLINK_EXEC(3)
2
3
4
6 dblink_exec - executes a command in a remote database
7
9 dblink_exec(text connname, text sql [, bool fail_on_error]) returns text
10 dblink_exec(text connstr, text sql [, bool fail_on_error]) returns text
11 dblink_exec(text sql [, bool fail_on_error]) returns text
12
14 dblink_exec executes a command (that is, any SQL statement that doesn't
15 return rows) in a remote database.
16
17 When two text arguments are given, the first one is first looked up as
18 a persistent connection's name; if found, the command is executed on
19 that connection. If not found, the first argument is treated as a
20 connection info string as for dblink_connect, and the indicated
21 connection is made just for the duration of this command.
22
24 connname
25 Name of the connection to use; omit this parameter to use the
26 unnamed connection.
27
28 connstr
29 A connection info string, as previously described for
30 dblink_connect.
31
32 sql
33 The SQL command that you wish to execute in the remote database,
34 for example insert into foo values(0, 'a', '{"a0","b0","c0"}').
35
36 fail_on_error
37 If true (the default when omitted) then an error thrown on the
38 remote side of the connection causes an error to also be thrown
39 locally. If false, the remote error is locally reported as a
40 NOTICE, and the function's return value is set to ERROR.
41
43 Returns status, either the command's status string or ERROR.
44
46 SELECT dblink_connect('dbname=dblink_test_standby');
47 dblink_connect
48 ----------------
49 OK
50 (1 row)
51
52 SELECT dblink_exec('insert into foo values(21, ''z'', ''{"a0","b0","c0"}'');');
53 dblink_exec
54 -----------------
55 INSERT 943366 1
56 (1 row)
57
58 SELECT dblink_connect('myconn', 'dbname=regression');
59 dblink_connect
60 ----------------
61 OK
62 (1 row)
63
64 SELECT dblink_exec('myconn', 'insert into foo values(21, ''z'', ''{"a0","b0","c0"}'');');
65 dblink_exec
66 ------------------
67 INSERT 6432584 1
68 (1 row)
69
70 SELECT dblink_exec('myconn', 'insert into pg_class values (''foo'')',false);
71 NOTICE: sql error
72 DETAIL: ERROR: null value in column "relnamespace" violates not-null constraint
73
74 dblink_exec
75 -------------
76 ERROR
77 (1 row)
78
79
80
81PostgreSQL 13.3 2021 DBLINK_EXEC(3)