2 .\" Title: dblink_build_sql_update
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "DBLINK_BUILD_SQL_UPDATE" "3" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 dblink_build_sql_update \- builds an UPDATE statement using a local tuple, replacing the primary key field values with alternative supplied values
35 dblink_build_sql_update(text relname,
36 int2vector primary_key_attnums,
37 integer num_primary_key_atts,
38 text[] src_pk_att_vals_array,
39 text[] tgt_pk_att_vals_array) returns text
43 \fBdblink_build_sql_update\fR
44 can be useful in doing selective replication of a local table to a remote database\&. It selects a row from the local table based on primary key, and then builds an SQL
46 command that will duplicate that row, but with the primary key values replaced by the values in the last argument\&. (To make an exact copy of the row, just specify the same values for the last two arguments\&.) The
48 command always assigns all fields of the row \(em the main difference between this and
49 \fBdblink_build_sql_insert\fR
50 is that it\*(Aqs assumed that the target row already exists in the remote table\&.
55 Name of a local relation, for example
58 myschema\&.mytab\&. Include double quotes if the name is mixed\-case or contains special characters, for example
59 "FooBar"; without quotes, the string will be folded to lower case\&.
62 \fIprimary_key_attnums\fR
64 Attribute numbers (1\-based) of the primary key fields, for example
68 \fInum_primary_key_atts\fR
70 The number of primary key fields\&.
73 \fIsrc_pk_att_vals_array\fR
75 Values of the primary key fields to be used to look up the local tuple\&. Each field is represented in text form\&. An error is thrown if there is no local row with these primary key values\&.
78 \fItgt_pk_att_vals_array\fR
80 Values of the primary key fields to be placed in the resulting
82 command\&. Each field is represented in text form\&.
86 Returns the requested SQL statement as text\&.
91 9\&.0, the attribute numbers in
92 \fIprimary_key_attnums\fR
93 are interpreted as logical column numbers, corresponding to the column\*(Aqs position in
94 SELECT * FROM relname\&. Previous versions interpreted the numbers as physical column positions\&. There is a difference if any column(s) to the left of the indicated column have been dropped during the lifetime of the table\&.
101 SELECT dblink_build_sql_update(\*(Aqfoo\*(Aq, \*(Aq1 2\*(Aq, 2, \*(Aq{"1", "a"}\*(Aq, \*(Aq{"1", "b"}\*(Aq);
102 dblink_build_sql_update
103 \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
104 UPDATE foo SET f1=\*(Aq1\*(Aq,f2=\*(Aqb\*(Aq,f3=\*(Aq1\*(Aq WHERE f1=\*(Aq1\*(Aq AND f2=\*(Aqb\*(Aq