gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

72 行
8.2KB

  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>ALTER VIEW</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="sql-alterusermapping.html" title="ALTER USER MAPPING" /><link rel="next" href="sql-analyze.html" title="ANALYZE" /></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">ALTER VIEW</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-alterusermapping.html" title="ALTER USER MAPPING">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</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="sql-analyze.html" title="ANALYZE">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-ALTERVIEW"><div class="titlepage"></div><a id="id-1.9.3.45.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ALTER VIEW</span></h2><p>ALTER VIEW — change the definition of a view</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> ALTER [ COLUMN ] <em class="replaceable"><code>column_name</code></em> SET DEFAULT <em class="replaceable"><code>expression</code></em>
  4. ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> ALTER [ COLUMN ] <em class="replaceable"><code>column_name</code></em> DROP DEFAULT
  5. ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_USER | SESSION_USER }
  6. ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> RENAME TO <em class="replaceable"><code>new_name</code></em>
  7. ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> SET SCHEMA <em class="replaceable"><code>new_schema</code></em>
  8. ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> SET ( <em class="replaceable"><code>view_option_name</code></em> [= <em class="replaceable"><code>view_option_value</code></em>] [, ... ] )
  9. ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> RESET ( <em class="replaceable"><code>view_option_name</code></em> [, ... ] )
  10. </pre></div><div class="refsect1" id="id-1.9.3.45.5"><h2>Description</h2><p>
  11. <code class="command">ALTER VIEW</code> changes various auxiliary properties
  12. of a view. (If you want to modify the view's defining query,
  13. use <code class="command">CREATE OR REPLACE VIEW</code>.)
  14. </p><p>
  15. You must own the view to use <code class="command">ALTER VIEW</code>.
  16. To change a view's schema, you must also have <code class="literal">CREATE</code>
  17. privilege on the new schema.
  18. To alter the owner, you must also be a direct or indirect member of the new
  19. owning role, and that role must have <code class="literal">CREATE</code> privilege on
  20. the view's schema. (These restrictions enforce that altering the owner
  21. doesn't do anything you couldn't do by dropping and recreating the view.
  22. However, a superuser can alter ownership of any view anyway.)
  23. </p></div><div class="refsect1" id="id-1.9.3.45.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
  24. The name (optionally schema-qualified) of an existing view.
  25. </p></dd><dt><span class="term"><code class="literal">IF EXISTS</code></span></dt><dd><p>
  26. Do not throw an error if the view does not exist. A notice is issued
  27. in this case.
  28. </p></dd><dt><span class="term"><code class="literal">SET</code>/<code class="literal">DROP DEFAULT</code></span></dt><dd><p>
  29. These forms set or remove the default value for a column.
  30. A view column's default value is substituted into any
  31. <code class="command">INSERT</code> or <code class="command">UPDATE</code> command whose target is the
  32. view, before applying any rules or triggers for the view. The view's
  33. default will therefore take precedence over any default values from
  34. underlying relations.
  35. </p></dd><dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt><dd><p>
  36. The user name of the new owner of the view.
  37. </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>
  38. The new name for the view.
  39. </p></dd><dt><span class="term"><em class="replaceable"><code>new_schema</code></em></span></dt><dd><p>
  40. The new schema for the view.
  41. </p></dd><dt><span class="term"><code class="literal">SET ( <em class="replaceable"><code>view_option_name</code></em> [= <em class="replaceable"><code>view_option_value</code></em>] [, ... ] )</code><br /></span><span class="term"><code class="literal">RESET ( <em class="replaceable"><code>view_option_name</code></em> [, ... ] )</code></span></dt><dd><p>
  42. Sets or resets a view option. Currently supported options are:
  43. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">check_option</code> (<code class="type">string</code>)</span></dt><dd><p>
  44. Changes the check option of the view. The value must
  45. be <code class="literal">local</code> or <code class="literal">cascaded</code>.
  46. </p></dd><dt><span class="term"><code class="literal">security_barrier</code> (<code class="type">boolean</code>)</span></dt><dd><p>
  47. Changes the security-barrier property of the view. The value must
  48. be Boolean value, such as <code class="literal">true</code>
  49. or <code class="literal">false</code>.
  50. </p></dd></dl></div><p>
  51. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.45.7"><h2>Notes</h2><p>
  52. For historical reasons, <code class="command">ALTER TABLE</code> can be used with
  53. views too; but the only variants of <code class="command">ALTER TABLE</code>
  54. that are allowed with views are equivalent to the ones shown above.
  55. </p></div><div class="refsect1" id="id-1.9.3.45.8"><h2>Examples</h2><p>
  56. To rename the view <code class="literal">foo</code> to
  57. <code class="literal">bar</code>:
  58. </p><pre class="programlisting">
  59. ALTER VIEW foo RENAME TO bar;
  60. </pre><p>
  61. </p><p>
  62. To attach a default column value to an updatable view:
  63. </p><pre class="programlisting">
  64. CREATE TABLE base_table (id int, ts timestamptz);
  65. CREATE VIEW a_view AS SELECT * FROM base_table;
  66. ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
  67. INSERT INTO base_table(id) VALUES(1); -- ts will receive a NULL
  68. INSERT INTO a_view(id) VALUES(2); -- ts will receive the current time
  69. </pre></div><div class="refsect1" id="id-1.9.3.45.9"><h2>Compatibility</h2><p>
  70. <code class="command">ALTER VIEW</code> is a <span class="productname">PostgreSQL</span>
  71. extension of the SQL standard.
  72. </p></div><div class="refsect1" id="id-1.9.3.45.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createview.html" title="CREATE VIEW"><span class="refentrytitle">CREATE VIEW</span></a>, <a class="xref" href="sql-dropview.html" title="DROP VIEW"><span class="refentrytitle">DROP VIEW</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-alterusermapping.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-analyze.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ALTER USER MAPPING </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ANALYZE</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1