1DBLINK_BUILD_SQL_UPDATE(3P)ostgreSQL 9.2.24 DocumentatiDoBnLINK_BUILD_SQL_UPDATE(3)
2
3
4

NAME

6       dblink_build_sql_update - builds an UPDATE statement using a local
7       tuple, replacing the primary key field values with alternative supplied
8       values
9

SYNOPSIS

11       dblink_build_sql_update(text relname,
12                               int2vector primary_key_attnums,
13                               integer num_primary_key_atts,
14                               text[] src_pk_att_vals_array,
15                               text[] tgt_pk_att_vals_array) returns text
16

DESCRIPTION

18       dblink_build_sql_update can be useful in doing selective replication of
19       a local table to a remote database. It selects a row from the local
20       table based on primary key, and then builds a SQL UPDATE command that
21       will duplicate that row, but with the primary key values replaced by
22       the values in the last argument. (To make an exact copy of the row,
23       just specify the same values for the last two arguments.) The UPDATE
24       command always assigns all fields of the row — the main difference
25       between this and dblink_build_sql_insert is that it's assumed that the
26       target row already exists in the remote table.
27

ARGUMENTS

29       relname
30           Name of a local relation, for example foo or myschema.mytab.
31           Include double quotes if the name is mixed-case or contains special
32           characters, for example "FooBar"; without quotes, the string will
33           be folded to lower case.
34
35       primary_key_attnums
36           Attribute numbers (1-based) of the primary key fields, for example
37           1 2.
38
39       num_primary_key_atts
40           The number of primary key fields.
41
42       src_pk_att_vals_array
43           Values of the primary key fields to be used to look up the local
44           tuple. Each field is represented in text form. An error is thrown
45           if there is no local row with these primary key values.
46
47       tgt_pk_att_vals_array
48           Values of the primary key fields to be placed in the resulting
49           UPDATE command. Each field is represented in text form.
50

RETURN VALUE

52       Returns the requested SQL statement as text.
53

NOTES

55       As of PostgreSQL 9.0, the attribute numbers in primary_key_attnums are
56       interpreted as logical column numbers, corresponding to the column's
57       position in SELECT * FROM relname. Previous versions interpreted the
58       numbers as physical column positions. There is a difference if any
59       column(s) to the left of the indicated column have been dropped during
60       the lifetime of the table.
61

EXAMPLES

63           SELECT dblink_build_sql_update('foo', '1 2', 2, '{"1", "a"}', '{"1", "b"}');
64                              dblink_build_sql_update
65           -------------------------------------------------------------
66            UPDATE foo SET f1='1',f2='b',f3='1' WHERE f1='1' AND f2='b'
67           (1 row)
68
69
70
71PostgreSQL 9.2.24                 2017-11-06        DBLINK_BUILD_SQL_UPDATE(3)
Impressum