1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>dblink_exec</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="contrib-dblink-function.html" title="dblink" /><link rel="next" href="contrib-dblink-open.html" title="dblink_open" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">dblink_exec</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="contrib-dblink-function.html" title="dblink">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="dblink.html" title="F.12. dblink — connect to other PostgreSQL databases">Up</a></td><th width="60%" align="center">F.12. dblink — connect to other PostgreSQL databases</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="contrib-dblink-open.html" title="dblink_open">Next</a></td></tr></table><hr /></div><div class="refentry" id="CONTRIB-DBLINK-EXEC"><div class="titlepage"></div><a id="id-1.11.7.22.9.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">dblink_exec</span></h2><p>dblink_exec — executes a command in a remote database</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="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
</pre></div><div class="refsect1" id="id-1.11.7.22.9.5"><h2>Description</h2><p>
<code class="function">dblink_exec</code> executes a command (that is, any SQL statement
that doesn't return rows) in a remote database.
</p><p>
When two <code class="type">text</code> 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 <code class="function">dblink_connect</code>,
and the indicated connection is made just for the duration of this command.
</p></div><div class="refsect1" id="id-1.11.7.22.9.6"><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>connname</code></em></span></dt><dd><p>
Name of the connection to use; omit this parameter to use the
unnamed connection.
</p></dd><dt><span class="term"><em class="parameter"><code>connstr</code></em></span></dt><dd><p>
A connection info string, as previously described for
<code class="function">dblink_connect</code>.
</p></dd><dt><span class="term"><em class="parameter"><code>sql</code></em></span></dt><dd><p>
The SQL command that you wish to execute in the remote database,
for example
<code class="literal">insert into foo values(0, 'a', '{"a0","b0","c0"}')</code>.
</p></dd><dt><span class="term"><em class="parameter"><code>fail_on_error</code></em></span></dt><dd><p>
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 <code class="literal">ERROR</code>.
</p></dd></dl></div></div><div class="refsect1" id="id-1.11.7.22.9.7"><h2>Return Value</h2><p>
Returns status, either the command's status string or <code class="literal">ERROR</code>.
</p></div><div class="refsect1" id="id-1.11.7.22.9.8"><h2>Examples</h2><pre class="screen">
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)
</pre></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="contrib-dblink-function.html" title="dblink">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="dblink.html" title="F.12. dblink — connect to other PostgreSQL databases">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="contrib-dblink-open.html" title="dblink_open">Next</a></td></tr><tr><td width="40%" align="left" valign="top">dblink </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> dblink_open</td></tr></table></div></body></html>
|