]> begriffs open source - ai-pg/blob - full-docs/txt/contrib-dblink-exec.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / contrib-dblink-exec.txt
1
2 dblink_exec
3
4    dblink_exec — executes a command in a remote database
5
6 Synopsis
7
8 dblink_exec(text connname, text sql [, bool fail_on_error]) returns text
9 dblink_exec(text connstr, text sql [, bool fail_on_error]) returns text
10 dblink_exec(text sql [, bool fail_on_error]) returns text
11
12 Description
13
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
23 Arguments
24
25    connname
26           Name of the connection to use; omit this parameter to use the
27           unnamed connection.
28
29    connstr
30           A connection info string, as previously described for
31           dblink_connect.
32
33    sql
34           The SQL command that you wish to execute in the remote database,
35           for example insert into foo values(0, 'a', '{"a0","b0","c0"}').
36
37    fail_on_error
38           If true (the default when omitted) then an error thrown on the
39           remote side of the connection causes an error to also be thrown
40           locally. If false, the remote error is locally reported as a
41           NOTICE, and the function's return value is set to ERROR.
42
43 Return Value
44
45    Returns status, either the command's status string or ERROR.
46
47 Examples
48
49 SELECT dblink_connect('dbname=dblink_test_standby');
50  dblink_connect
51 ----------------
52  OK
53 (1 row)
54
55 SELECT dblink_exec('insert into foo values(21, ''z'', ''{"a0","b0","c0"}'');');
56    dblink_exec
57 -----------------
58  INSERT 943366 1
59 (1 row)
60
61 SELECT dblink_connect('myconn', 'dbname=regression');
62  dblink_connect
63 ----------------
64  OK
65 (1 row)
66
67 SELECT dblink_exec('myconn', 'insert into foo values(21, ''z'', ''{"a0","b0","c0
68 "}'');');
69    dblink_exec
70 ------------------
71  INSERT 6432584 1
72 (1 row)
73
74 SELECT dblink_exec('myconn', 'insert into pg_class values (''foo'')',false);
75 NOTICE:  sql error
76 DETAIL:  ERROR:  null value in column "relnamespace" violates not-null constrain
77 t
78
79  dblink_exec
80 -------------
81  ERROR
82 (1 row)