|
- <?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 V1.79.1" /><link rel="prev" href="contrib-dblink-function.html" title="dblink" /><link rel="next" href="contrib-dblink-open.html" title="dblink_open" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" 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.10. dblink">Up</a></td><th width="60%" align="center">F.10. dblink</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 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></hr></div><div class="refentry" id="CONTRIB-DBLINK-EXEC"><div class="titlepage"></div><a id="id-1.11.7.19.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.19.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.19.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.19.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.19.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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="dblink.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="contrib-dblink-open.html">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">Home</a></td><td width="40%" align="right" valign="top"> dblink_open</td></tr></table></div></body></html>
|