blob: 403c8a8dd6416df31065dcc88984e991f6f3b7f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!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>REFRESH 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 Vsnapshot" /><link rel="prev" href="sql-reassign-owned.html" title="REASSIGN OWNED" /><link rel="next" href="sql-reindex.html" title="REINDEX" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">REFRESH MATERIALIZED VIEW</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-reassign-owned.html" title="REASSIGN OWNED">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 15.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-reindex.html" title="REINDEX">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-REFRESHMATERIALIZEDVIEW"><div class="titlepage"></div><a id="id-1.9.3.162.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">REFRESH MATERIALIZED VIEW</span></h2><p>REFRESH MATERIALIZED VIEW — replace the contents of a materialized view</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] <em class="replaceable"><code>name</code></em>
[ WITH [ NO ] DATA ]
</pre></div><div class="refsect1" id="id-1.9.3.162.5"><h2>Description</h2><p>
<code class="command">REFRESH MATERIALIZED VIEW</code> completely replaces the
contents of a materialized view. To execute this command you must be the
owner of the materialized view. The old contents are discarded. If
<code class="literal">WITH DATA</code> is specified (or defaults) the backing query
is executed to provide the new data, and the materialized view is left in a
scannable state. If <code class="literal">WITH NO DATA</code> is specified no new
data is generated and the materialized view is left in an unscannable
state.
</p><p>
<code class="literal">CONCURRENTLY</code> and <code class="literal">WITH NO DATA</code> may not
be specified together.
</p></div><div class="refsect1" id="id-1.9.3.162.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">CONCURRENTLY</code></span></dt><dd><p>
Refresh the materialized view without locking out concurrent selects on
the materialized view. Without this option a refresh which affects a
lot of rows will tend to use fewer resources and complete more quickly,
but could block other connections which are trying to read from the
materialized view. This option may be faster in cases where a small
number of rows are affected.
</p><p>
This option is only allowed if there is at least one
<code class="literal">UNIQUE</code> index on the materialized view which uses only
column names and includes all rows; that is, it must not be an
expression index or include a <code class="literal">WHERE</code> clause.
</p><p>
This option may not be used when the materialized view is not already
populated.
</p><p>
Even with this option only one <code class="literal">REFRESH</code> at a time may
run against any one materialized view.
</p></dd><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
The name (optionally schema-qualified) of the materialized view to
refresh.
</p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.162.7"><h2>Notes</h2><p>
If there is an <code class="literal">ORDER BY</code> clause in the materialized
view's defining query, the original contents of the materialized view
will be ordered that way; but <code class="command">REFRESH MATERIALIZED
VIEW</code> does not guarantee to preserve that ordering.
</p></div><div class="refsect1" id="id-1.9.3.162.8"><h2>Examples</h2><p>
This command will replace the contents of the materialized view called
<code class="literal">order_summary</code> using the query from the materialized
view's definition, and leave it in a scannable state:
</p><pre class="programlisting">
REFRESH MATERIALIZED VIEW order_summary;
</pre><p>
</p><p>
This command will free storage associated with the materialized view
<code class="literal">annual_statistics_basis</code> and leave it in an unscannable
state:
</p><pre class="programlisting">
REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;
</pre></div><div class="refsect1" id="id-1.9.3.162.9"><h2>Compatibility</h2><p>
<code class="command">REFRESH MATERIALIZED VIEW</code> is a
<span class="productname">PostgreSQL</span> extension.
</p></div><div class="refsect1" id="id-1.9.3.162.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-creatematerializedview.html" title="CREATE MATERIALIZED VIEW"><span class="refentrytitle">CREATE MATERIALIZED VIEW</span></a>, <a class="xref" href="sql-altermaterializedview.html" title="ALTER MATERIALIZED VIEW"><span class="refentrytitle">ALTER MATERIALIZED VIEW</span></a>, <a class="xref" href="sql-dropmaterializedview.html" title="DROP MATERIALIZED VIEW"><span class="refentrytitle">DROP 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-reassign-owned.html" title="REASSIGN OWNED">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-reindex.html" title="REINDEX">Next</a></td></tr><tr><td width="40%" align="left" valign="top">REASSIGN OWNED </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 15.4 Documentation">Home</a></td><td width="40%" align="right" valign="top"> REINDEX</td></tr></table></div></body></html>
|