gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

52 linhas
5.9KB

  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_insert</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 V1.79.1" /><link rel="prev" href="contrib-dblink-get-pkey.html" title="dblink_get_pkey" /><link rel="next" href="contrib-dblink-build-sql-delete.html" title="dblink_build_sql_delete" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">dblink_build_sql_insert</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="contrib-dblink-get-pkey.html" title="dblink_get_pkey">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="dblink.html" title="F.10. dblink">Up</a></td><th width="60%" align="center">F.10. dblink</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="contrib-dblink-build-sql-delete.html" title="dblink_build_sql_delete">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="CONTRIB-DBLINK-BUILD-SQL-INSERT"><div class="titlepage"></div><a id="id-1.11.7.19.21.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">dblink_build_sql_insert</span></h2><p>dblink_build_sql_insert —
  3. builds an INSERT statement using a local tuple, replacing the
  4. primary key field values with alternative supplied values
  5. </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  6. dblink_build_sql_insert(text relname,
  7. int2vector primary_key_attnums,
  8. integer num_primary_key_atts,
  9. text[] src_pk_att_vals_array,
  10. text[] tgt_pk_att_vals_array) returns text
  11. </pre></div><div class="refsect1" id="id-1.11.7.19.21.5"><h2>Description</h2><p>
  12. <code class="function">dblink_build_sql_insert</code> can be useful in doing selective
  13. replication of a local table to a remote database. It selects a row
  14. from the local table based on primary key, and then builds a SQL
  15. <code class="command">INSERT</code> command that will duplicate that row, but with
  16. the primary key values replaced by the values in the last argument.
  17. (To make an exact copy of the row, just specify the same values for
  18. the last two arguments.)
  19. </p></div><div class="refsect1" id="id-1.11.7.19.21.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>
  20. Name of a local relation, for example <code class="literal">foo</code> or
  21. <code class="literal">myschema.mytab</code>. Include double quotes if the
  22. name is mixed-case or contains special characters, for
  23. example <code class="literal">"FooBar"</code>; without quotes, the string
  24. will be folded to lower case.
  25. </p></dd><dt><span class="term"><em class="parameter"><code>primary_key_attnums</code></em></span></dt><dd><p>
  26. Attribute numbers (1-based) of the primary key fields,
  27. for example <code class="literal">1 2</code>.
  28. </p></dd><dt><span class="term"><em class="parameter"><code>num_primary_key_atts</code></em></span></dt><dd><p>
  29. The number of primary key fields.
  30. </p></dd><dt><span class="term"><em class="parameter"><code>src_pk_att_vals_array</code></em></span></dt><dd><p>
  31. Values of the primary key fields to be used to look up the
  32. local tuple. Each field is represented in text form.
  33. An error is thrown if there is no local row with these
  34. primary key values.
  35. </p></dd><dt><span class="term"><em class="parameter"><code>tgt_pk_att_vals_array</code></em></span></dt><dd><p>
  36. Values of the primary key fields to be placed in the resulting
  37. <code class="command">INSERT</code> command. Each field is represented in text form.
  38. </p></dd></dl></div></div><div class="refsect1" id="id-1.11.7.19.21.7"><h2>Return Value</h2><p>Returns the requested SQL statement as text.</p></div><div class="refsect1" id="id-1.11.7.19.21.8"><h2>Notes</h2><p>
  39. As of <span class="productname">PostgreSQL</span> 9.0, the attribute numbers in
  40. <em class="parameter"><code>primary_key_attnums</code></em> are interpreted as logical
  41. column numbers, corresponding to the column's position in
  42. <code class="literal">SELECT * FROM relname</code>. Previous versions interpreted the
  43. numbers as physical column positions. There is a difference if any
  44. column(s) to the left of the indicated column have been dropped during
  45. the lifetime of the table.
  46. </p></div><div class="refsect1" id="id-1.11.7.19.21.9"><h2>Examples</h2><pre class="screen">
  47. SELECT dblink_build_sql_insert('foo', '1 2', 2, '{"1", "a"}', '{"1", "b''a"}');
  48. dblink_build_sql_insert
  49. --------------------------------------------------
  50. INSERT INTO foo(f1,f2,f3) VALUES('1','b''a','1')
  51. (1 row)
  52. </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-get-pkey.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="dblink.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="contrib-dblink-build-sql-delete.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">dblink_get_pkey </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> dblink_build_sql_delete</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1