codekingpro/portable-devtools
115k
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 Vsnapshot" /><link rel="prev" href="sql-alterusermapping.html" title="ALTER USER MAPPING" /><link rel="next" href="sql-analyze.html" title="ANALYZE" /></head><body id="docContent" class="container-fluid col-10"><div 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 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-analyze.html" title="ANALYZE">Next</a></td></tr></table><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">3ALTER 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>4ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> ALTER [ COLUMN ] <em class="replaceable"><code>column_name</code></em> DROP DEFAULT5ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }6ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> RENAME [ COLUMN ] <em class="replaceable"><code>column_name</code></em> TO <em class="replaceable"><code>new_column_name</code></em>7ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> RENAME TO <em class="replaceable"><code>new_name</code></em>8ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> SET SCHEMA <em class="replaceable"><code>new_schema</code></em>9ALTER 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>] [, ... ] )10ALTER VIEW [ IF EXISTS ] <em class="replaceable"><code>name</code></em> RESET ( <em class="replaceable"><code>view_option_name</code></em> [, ... ] )11</pre></div><div class="refsect1" id="id-1.9.3.45.5"><h2>Description</h2><p>12 <code class="command">ALTER VIEW</code> changes various auxiliary properties13 of a view. (If you want to modify the view's defining query,14 use <code class="command">CREATE OR REPLACE VIEW</code>.)15 </p><p>16 You must own the view to use <code class="command">ALTER VIEW</code>.17 To change a view's schema, you must also have <code class="literal">CREATE</code>18 privilege on the new schema.19 To alter the owner, you must be able to <code class="literal">SET ROLE</code> to the20 new owning role, and that role must have <code class="literal">CREATE</code>21 privilege on the view's schema.22 (These restrictions enforce that altering the owner23 doesn't do anything you couldn't do by dropping and recreating the view.24 However, a superuser can alter ownership of any view anyway.)25 </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>26 The name (optionally schema-qualified) of an existing view.27 </p></dd><dt><span class="term"><em class="replaceable"><code>column_name</code></em></span></dt><dd><p>28 Name of an existing column.29 </p></dd><dt><span class="term"><em class="replaceable"><code>new_column_name</code></em></span></dt><dd><p>30 New name for an existing column.31 </p></dd><dt><span class="term"><code class="literal">IF EXISTS</code></span></dt><dd><p>32 Do not throw an error if the view does not exist. A notice is issued33 in this case.34 </p></dd><dt><span class="term"><code class="literal">SET</code>/<code class="literal">DROP DEFAULT</code></span></dt><dd><p>35 These forms set or remove the default value for a column.36 A view column's default value is substituted into any37 <code class="command">INSERT</code> or <code class="command">UPDATE</code> command whose target is the38 view, before applying any rules or triggers for the view. The view's39 default will therefore take precedence over any default values from40 underlying relations.41 </p></dd><dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt><dd><p>42 The user name of the new owner of the view.43 </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>44 The new name for the view.45 </p></dd><dt><span class="term"><em class="replaceable"><code>new_schema</code></em></span></dt><dd><p>46 The new schema for the view.47 </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>48 Sets or resets a view option. Currently supported options are:49 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">check_option</code> (<code class="type">enum</code>)</span></dt><dd><p>50 Changes the check option of the view. The value must51 be <code class="literal">local</code> or <code class="literal">cascaded</code>.52 </p></dd><dt><span class="term"><code class="literal">security_barrier</code> (<code class="type">boolean</code>)</span></dt><dd><p>53 Changes the security-barrier property of the view. The value must54 be a Boolean value, such as <code class="literal">true</code>55 or <code class="literal">false</code>.56 </p></dd><dt><span class="term"><code class="literal">security_invoker</code> (<code class="type">boolean</code>)</span></dt><dd><p>57 Changes the security-invoker property of the view. The value must58 be a Boolean value, such as <code class="literal">true</code>59 or <code class="literal">false</code>.60 </p></dd></dl></div></dd></dl></div></div><div class="refsect1" id="id-1.9.3.45.7"><h2>Notes</h2><p>61 For historical reasons, <code class="command">ALTER TABLE</code> can be used with62 views too; but the only variants of <code class="command">ALTER TABLE</code>63 that are allowed with views are equivalent to the ones shown above.64 </p></div><div class="refsect1" id="id-1.9.3.45.8"><h2>Examples</h2><p>65 To rename the view <code class="literal">foo</code> to66 <code class="literal">bar</code>:67</p><pre class="programlisting">68ALTER VIEW foo RENAME TO bar;69</pre><p>70 </p><p>71 To attach a default column value to an updatable view:72</p><pre class="programlisting">73CREATE TABLE base_table (id int, ts timestamptz);74CREATE VIEW a_view AS SELECT * FROM base_table;75ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();76INSERT INTO base_table(id) VALUES(1); -- ts will receive a NULL77INSERT INTO a_view(id) VALUES(2); -- ts will receive the current time78</pre></div><div class="refsect1" id="id-1.9.3.45.9"><h2>Compatibility</h2><p>79 <code class="command">ALTER VIEW</code> is a <span class="productname">PostgreSQL</span>80 extension of the SQL standard.81 </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" title="ALTER USER MAPPING">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-analyze.html" title="ANALYZE">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" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> ANALYZE</td></tr></table></div></body></html>