]> begriffs open source - ai-pg/blob - full-docs/html/contrib-dblink-build-sql-update.html
Include latest toc output
[ai-pg] / full-docs / html / contrib-dblink-build-sql-update.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>dblink_build_sql_update</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="contrib-dblink-build-sql-delete.html" title="dblink_build_sql_delete" /><link rel="next" href="dict-int.html" title="F.12. dict_int — example full-text search dictionary for integers" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">dblink_build_sql_update</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="contrib-dblink-build-sql-delete.html" title="dblink_build_sql_delete">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="dblink.html" title="F.11. dblink — connect to other PostgreSQL databases">Up</a></td><th width="60%" align="center">F.11. dblink — connect to other PostgreSQL databases</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="dict-int.html" title="F.12. dict_int —&#10;   example full-text search dictionary for integers">Next</a></td></tr></table><hr /></div><div class="refentry" id="CONTRIB-DBLINK-BUILD-SQL-UPDATE"><div class="titlepage"></div><a id="id-1.11.7.21.25.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">dblink_build_sql_update</span></h2><p>dblink_build_sql_update — builds an UPDATE statement using a local tuple, replacing
3     the primary key field values with alternative supplied values
4    </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
5 dblink_build_sql_update(text relname,
6                         int2vector primary_key_attnums,
7                         integer num_primary_key_atts,
8                         text[] src_pk_att_vals_array,
9                         text[] tgt_pk_att_vals_array) returns text
10 </pre></div><div class="refsect1" id="id-1.11.7.21.25.5"><h2>Description</h2><p>
11     <code class="function">dblink_build_sql_update</code> can be useful in doing selective
12     replication of a local table to a remote database.  It selects a row
13     from the local table based on primary key, and then builds an SQL
14     <code class="command">UPDATE</code> command that will duplicate that row, but with
15     the primary key values replaced by the values in the last argument.
16     (To make an exact copy of the row, just specify the same values for
17     the last two arguments.)  The <code class="command">UPDATE</code> command always assigns
18     all fields of the row — the main difference between this and
19     <code class="function">dblink_build_sql_insert</code> is that it's assumed that
20     the target row already exists in the remote table.
21    </p></div><div class="refsect1" id="id-1.11.7.21.25.6"><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>relname</code></em></span></dt><dd><p>
22        Name of a local relation, for example <code class="literal">foo</code> or
23        <code class="literal">myschema.mytab</code>.  Include double quotes if the
24        name is mixed-case or contains special characters, for
25        example <code class="literal">"FooBar"</code>; without quotes, the string
26        will be folded to lower case.
27       </p></dd><dt><span class="term"><em class="parameter"><code>primary_key_attnums</code></em></span></dt><dd><p>
28        Attribute numbers (1-based) of the primary key fields,
29        for example <code class="literal">1 2</code>.
30       </p></dd><dt><span class="term"><em class="parameter"><code>num_primary_key_atts</code></em></span></dt><dd><p>
31        The number of primary key fields.
32       </p></dd><dt><span class="term"><em class="parameter"><code>src_pk_att_vals_array</code></em></span></dt><dd><p>
33        Values of the primary key fields to be used to look up the
34        local tuple.  Each field is represented in text form.
35        An error is thrown if there is no local row with these
36        primary key values.
37       </p></dd><dt><span class="term"><em class="parameter"><code>tgt_pk_att_vals_array</code></em></span></dt><dd><p>
38        Values of the primary key fields to be placed in the resulting
39        <code class="command">UPDATE</code> command.  Each field is represented in text form.
40       </p></dd></dl></div></div><div class="refsect1" id="id-1.11.7.21.25.7"><h2>Return Value</h2><p>Returns the requested SQL statement as text.</p></div><div class="refsect1" id="id-1.11.7.21.25.8"><h2>Notes</h2><p>
41     As of <span class="productname">PostgreSQL</span> 9.0, the attribute numbers in
42     <em class="parameter"><code>primary_key_attnums</code></em> are interpreted as logical
43     column numbers, corresponding to the column's position in
44     <code class="literal">SELECT * FROM relname</code>.  Previous versions interpreted the
45     numbers as physical column positions.  There is a difference if any
46     column(s) to the left of the indicated column have been dropped during
47     the lifetime of the table.
48    </p></div><div class="refsect1" id="id-1.11.7.21.25.9"><h2>Examples</h2><pre class="screen">
49 SELECT dblink_build_sql_update('foo', '1 2', 2, '{"1", "a"}', '{"1", "b"}');
50                    dblink_build_sql_update
51 -------------------------------------------------------------
52  UPDATE foo SET f1='1',f2='b',f3='1' WHERE f1='1' AND f2='b'
53 (1 row)
54 </pre></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="contrib-dblink-build-sql-delete.html" title="dblink_build_sql_delete">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="dblink.html" title="F.11. dblink — connect to other PostgreSQL databases">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="dict-int.html" title="F.12. dict_int —&#10;   example full-text search dictionary for integers">Next</a></td></tr><tr><td width="40%" align="left" valign="top">dblink_build_sql_delete </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> F.12. dict_int —
55    example full-text search dictionary for integers</td></tr></table></div></body></html>