2 dblink_build_sql_insert
4 dblink_build_sql_insert — builds an INSERT statement using a local
5 tuple, replacing the primary key field values with alternative supplied
10 dblink_build_sql_insert(text relname,
11 int2vector primary_key_attnums,
12 integer num_primary_key_atts,
13 text[] src_pk_att_vals_array,
14 text[] tgt_pk_att_vals_array) returns text
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 an 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.)
28 Name of a local relation, for example foo or myschema.mytab.
29 Include double quotes if the name is mixed-case or contains
30 special characters, for example "FooBar"; without quotes, the
31 string will be folded to lower case.
34 Attribute numbers (1-based) of the primary key fields, for
38 The number of primary key fields.
41 Values of the primary key fields to be used to look up the local
42 tuple. Each field is represented in text form. An error is
43 thrown if there is no local row with these primary key values.
46 Values of the primary key fields to be placed in the resulting
47 INSERT command. Each field is represented in text form.
51 Returns the requested SQL statement as text.
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.
64 SELECT dblink_build_sql_insert('foo', '1 2', 2, '{"1", "a"}', '{"1", "b''a"}');
65 dblink_build_sql_insert
66 --------------------------------------------------
67 INSERT INTO foo(f1,f2,f3) VALUES('1','b''a','1')