gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

63 lines
8.4KB

  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>CREATE MATERIALIZED 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-createlanguage.html" title="CREATE LANGUAGE" /><link rel="next" href="sql-createoperator.html" title="CREATE OPERATOR" /></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">CREATE MATERIALIZED VIEW</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createlanguage.html" title="CREATE LANGUAGE">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-createoperator.html" title="CREATE OPERATOR">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-CREATEMATERIALIZEDVIEW"><div class="titlepage"></div><a id="id-1.9.3.71.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE MATERIALIZED VIEW</span></h2><p>CREATE MATERIALIZED VIEW — define a new materialized view</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] <em class="replaceable"><code>table_name</code></em>
  4. [ (<em class="replaceable"><code>column_name</code></em> [, ...] ) ]
  5. [ USING <em class="replaceable"><code>method</code></em> ]
  6. [ WITH ( <em class="replaceable"><code>storage_parameter</code></em> [= <em class="replaceable"><code>value</code></em>] [, ... ] ) ]
  7. [ TABLESPACE <em class="replaceable"><code>tablespace_name</code></em> ]
  8. AS <em class="replaceable"><code>query</code></em>
  9. [ WITH [ NO ] DATA ]
  10. </pre></div><div class="refsect1" id="id-1.9.3.71.5"><h2>Description</h2><p>
  11. <code class="command">CREATE MATERIALIZED VIEW</code> defines a materialized view of
  12. a query. The query is executed and used to populate the view at the time
  13. the command is issued (unless <code class="command">WITH NO DATA</code> is used) and may be
  14. refreshed later using <code class="command">REFRESH MATERIALIZED VIEW</code>.
  15. </p><p>
  16. <code class="command">CREATE MATERIALIZED VIEW</code> is similar to
  17. <code class="command">CREATE TABLE AS</code>, except that it also remembers the query used
  18. to initialize the view, so that it can be refreshed later upon demand.
  19. A materialized view has many of the same properties as a table, but there
  20. is no support for temporary materialized views.
  21. </p></div><div class="refsect1" id="id-1.9.3.71.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">IF NOT EXISTS</code></span></dt><dd><p>
  22. Do not throw an error if a materialized view with the same name already
  23. exists. A notice is issued in this case. Note that there is no guarantee
  24. that the existing materialized view is anything like the one that would
  25. have been created.
  26. </p></dd><dt><span class="term"><em class="replaceable"><code>table_name</code></em></span></dt><dd><p>
  27. The name (optionally schema-qualified) of the materialized view to be
  28. created.
  29. </p></dd><dt><span class="term"><em class="replaceable"><code>column_name</code></em></span></dt><dd><p>
  30. The name of a column in the new materialized view. If column names are
  31. not provided, they are taken from the output column names of the query.
  32. </p></dd><dt><span class="term"><code class="literal">USING <em class="replaceable"><code>method</code></em></code></span></dt><dd><p>
  33. This optional clause specifies the table access method to use to store
  34. the contents for the new materialized view; the method needs be an
  35. access method of type <code class="literal">TABLE</code>. See <a class="xref" href="tableam.html" title="Chapter 60. Table Access Method Interface Definition">Chapter 60</a> for more information. If this option is not
  36. specified, the default table access method is chosen for the new
  37. materialized view. See <a class="xref" href="runtime-config-client.html#GUC-DEFAULT-TABLE-ACCESS-METHOD">default_table_access_method</a>
  38. for more information.
  39. </p></dd><dt><span class="term"><code class="literal">WITH ( <em class="replaceable"><code>storage_parameter</code></em> [= <em class="replaceable"><code>value</code></em>] [, ... ] )</code></span></dt><dd><p>
  40. This clause specifies optional storage parameters for the new
  41. materialized view; see <a class="xref" href="sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS" title="Storage Parameters">Storage Parameters</a> for more
  42. information. All parameters supported for <code class="literal">CREATE
  43. TABLE</code> are also supported for <code class="literal">CREATE MATERIALIZED
  44. VIEW</code>.
  45. See <a class="xref" href="sql-createtable.html" title="CREATE TABLE"><span class="refentrytitle">CREATE TABLE</span></a> for more information.
  46. </p></dd><dt><span class="term"><code class="literal">TABLESPACE <em class="replaceable"><code>tablespace_name</code></em></code></span></dt><dd><p>
  47. The <em class="replaceable"><code>tablespace_name</code></em> is the name
  48. of the tablespace in which the new materialized view is to be created.
  49. If not specified, <a class="xref" href="runtime-config-client.html#GUC-DEFAULT-TABLESPACE">default_tablespace</a> is consulted.
  50. </p></dd><dt><span class="term"><em class="replaceable"><code>query</code></em></span></dt><dd><p>
  51. A <a class="xref" href="sql-select.html" title="SELECT"><span class="refentrytitle">SELECT</span></a>, <a class="link" href="sql-select.html#SQL-TABLE" title="TABLE Command">TABLE</a>,
  52. or <a class="xref" href="sql-values.html" title="VALUES"><span class="refentrytitle">VALUES</span></a> command. This query will run within a
  53. security-restricted operation; in particular, calls to functions that
  54. themselves create temporary tables will fail.
  55. </p></dd><dt><span class="term"><code class="literal">WITH [ NO ] DATA</code></span></dt><dd><p>
  56. This clause specifies whether or not the materialized view should be
  57. populated at creation time. If not, the materialized view will be
  58. flagged as unscannable and cannot be queried until <code class="command">REFRESH
  59. MATERIALIZED VIEW</code> is used.
  60. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.71.7"><h2>Compatibility</h2><p>
  61. <code class="command">CREATE MATERIALIZED VIEW</code> is a
  62. <span class="productname">PostgreSQL</span> extension.
  63. </p></div><div class="refsect1" id="id-1.9.3.71.8"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-altermaterializedview.html" title="ALTER MATERIALIZED VIEW"><span class="refentrytitle">ALTER MATERIALIZED VIEW</span></a>, <a class="xref" href="sql-createtableas.html" title="CREATE TABLE AS"><span class="refentrytitle">CREATE TABLE AS</span></a>, <a class="xref" href="sql-createview.html" title="CREATE VIEW"><span class="refentrytitle">CREATE VIEW</span></a>, <a class="xref" href="sql-dropmaterializedview.html" title="DROP MATERIALIZED VIEW"><span class="refentrytitle">DROP MATERIALIZED VIEW</span></a>, <a class="xref" href="sql-refreshmaterializedview.html" title="REFRESH MATERIALIZED VIEW"><span class="refentrytitle">REFRESH MATERIALIZED 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-createlanguage.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-createoperator.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE LANGUAGE </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> CREATE OPERATOR</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1