1DBLINK_BUILD_SQL_INSERT(3)PostgreSQL 13.3 DocumentatioDnBLINK_BUILD_SQL_INSERT(3)
2
3
4

NAME

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

SYNOPSIS

11       dblink_build_sql_insert(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_insert 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 INSERT 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.)
24

ARGUMENTS

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

RETURN VALUE

49       Returns the requested SQL statement as text.
50

NOTES

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

EXAMPLES

60           SELECT dblink_build_sql_insert('foo', '1 2', 2, '{"1", "a"}', '{"1", "b''a"}');
61                        dblink_build_sql_insert
62           --------------------------------------------------
63            INSERT INTO foo(f1,f2,f3) VALUES('1','b''a','1')
64           (1 row)
65
66
67
68PostgreSQL 13.3                      2021           DBLINK_BUILD_SQL_INSERT(3)
Impressum