'\" t .\" Title: dblink_exec .\" Author: The PostgreSQL Global Development Group .\" Generator: DocBook XSL Stylesheets v1.75.2 .\" Date: 2016 .\" Manual: PostgreSQL 9.5.2 Documentation .\" Source: PostgreSQL 9.5.2 .\" Language: English .\" .TH "DBLINK_EXEC" "3" "2016" "PostgreSQL 9.5.2" "PostgreSQL 9.5.2 Documentation" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dblink_exec \- executes a command in a remote database .SH "SYNOPSIS" .sp .nf 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 .fi .SH "DESCRIPTION" .PP \fBdblink_exec\fR executes a command (that is, any SQL statement that doesn\(aqt return rows) in a remote database\&. .PP When two text arguments are given, the first one is first looked up as a persistent connection\(aqs 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 \fBdblink_connect\fR, and the indicated connection is made just for the duration of this command\&. .SH "ARGUMENTS" .PP \fIconnname\fR .RS 4 Name of the connection to use; omit this parameter to use the unnamed connection\&. .RE .PP \fIconnstr\fR .RS 4 A connection info string, as previously described for \fBdblink_connect\fR\&. .RE .PP \fIsql\fR .RS 4 The SQL command that you wish to execute in the remote database, for example insert into foo values(0,\(aqa\(aq,\(aq{"a0","b0","c0"}\(aq)\&. .RE .PP \fIfail_on_error\fR .RS 4 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\(aqs return value is set to ERROR\&. .RE .SH "RETURN VALUE" .PP Returns status, either the command\(aqs status string or ERROR\&. .SH "EXAMPLES" .sp .if n \{\ .RS 4 .\} .nf SELECT dblink_connect(\(aqdbname=dblink_test_standby\(aq); dblink_connect \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- OK (1 row) SELECT dblink_exec(\(aqinsert into foo values(21,\(aq\(aqz\(aq\(aq,\(aq\(aq{"a0","b0","c0"}\(aq\(aq);\(aq); dblink_exec \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- INSERT 943366 1 (1 row) SELECT dblink_connect(\(aqmyconn\(aq, \(aqdbname=regression\(aq); dblink_connect \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- OK (1 row) SELECT dblink_exec(\(aqmyconn\(aq, \(aqinsert into foo values(21,\(aq\(aqz\(aq\(aq,\(aq\(aq{"a0","b0","c0"}\(aq\(aq);\(aq); dblink_exec \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- INSERT 6432584 1 (1 row) SELECT dblink_exec(\(aqmyconn\(aq, \(aqinsert into pg_class values (\(aq\(aqfoo\(aq\(aq)\(aq,false); NOTICE: sql error DETAIL: ERROR: null value in column "relnamespace" violates not\-null constraint dblink_exec \-\-\-\-\-\-\-\-\-\-\-\-\- ERROR (1 row) .fi .if n \{\ .RE .\}