]> begriffs open source - ai-pg/blob - full-docs/man3/dblink_build_sql_update.3
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man3 / dblink_build_sql_update.3
1 '\" t
2 .\"     Title: dblink_build_sql_update
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 dblink_build_sql_update \- builds an UPDATE statement using a local tuple, replacing the primary key field values with alternative supplied values
32 .SH "SYNOPSIS"
33 .sp
34 .nf
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
40 .fi
41 .SH "DESCRIPTION"
42 .PP
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
45 \fBUPDATE\fR
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
47 \fBUPDATE\fR
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\&.
51 .SH "ARGUMENTS"
52 .PP
53 \fIrelname\fR
54 .RS 4
55 Name of a local relation, for example
56 foo
57 or
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\&.
60 .RE
61 .PP
62 \fIprimary_key_attnums\fR
63 .RS 4
64 Attribute numbers (1\-based) of the primary key fields, for example
65 1 2\&.
66 .RE
67 .PP
68 \fInum_primary_key_atts\fR
69 .RS 4
70 The number of primary key fields\&.
71 .RE
72 .PP
73 \fIsrc_pk_att_vals_array\fR
74 .RS 4
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\&.
76 .RE
77 .PP
78 \fItgt_pk_att_vals_array\fR
79 .RS 4
80 Values of the primary key fields to be placed in the resulting
81 \fBUPDATE\fR
82 command\&. Each field is represented in text form\&.
83 .RE
84 .SH "RETURN VALUE"
85 .PP
86 Returns the requested SQL statement as text\&.
87 .SH "NOTES"
88 .PP
89 As of
90 PostgreSQL
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\&.
95 .SH "EXAMPLES"
96 .sp
97 .if n \{\
98 .RS 4
99 .\}
100 .nf
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
105 (1 row)
106 .fi
107 .if n \{\
108 .RE
109 .\}