dblink_build_sql_update

Name

dblink_build_sql_update -- builds an update statement using a local tuple, replacing the selection key field values with alternate supplied values

Synopsis

 dblink_build_sql_update(text relname
                          ,int2vector primary_key_attnums
                          ,int2 num_primary_key_atts
                          ,_text src_pk_att_vals_array
                          ,_text tgt_pk_att_vals_array) RETURNS text
   

Inputs

relname

any relation name; e.g. 'foobar';

primary_key_attnums

vector of primary key attnums (1 based, see pg_index.indkey); e.g. '1 2'

num_primary_key_atts

number of primary key attnums in the vector; e.g. 2

src_pk_att_vals_array

array of primary key values, used to look up the local matching tuple, the values of which are then used to construct the SQL statement

tgt_pk_att_vals_array

array of primary key values, used to replace the local tuple values in the SQL statement

Outputs

Returns text -- requested SQL statement

Example

 test=# select dblink_build_sql_update('foo','1 2',2,'{"1", "a"}','{"1", "b"}');
                    dblink_build_sql_update
 -------------------------------------------------------------
  UPDATE foo SET f1='1',f2='b',f3='1' WHERE f1='1' AND f2='b'
 (1 row)