Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/ref/alter_view.sgml`
245217bddfcba20c2be8ff5cc6cc3ca6e44709921b2d21eb0000000100000f35
<!--
doc/src/sgml/ref/alter_view.sgml
PostgreSQL documentation
-->

<refentry id="sql-alterview">
 <indexterm zone="sql-alterview">
  <primary>ALTER VIEW</primary>
 </indexterm>

 <refmeta>
  <refentrytitle>ALTER VIEW</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>ALTER VIEW</refname>
  <refpurpose>change the definition of a view</refpurpose>
 </refnamediv>

 <refsynopsisdiv>
<synopsis>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> SET DEFAULT <replaceable class="parameter">expression</replaceable>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ALTER [ COLUMN ] <replaceable class="parameter">column_name</replaceable> DROP DEFAULT
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> OWNER TO { <replaceable class="parameter">new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RENAME [ COLUMN ] <replaceable class="parameter">column_name</replaceable> TO <replaceable class="parameter">new_column_name</replaceable>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> SET ( <replaceable class="parameter">view_option_name</replaceable> [= <replaceable class="parameter">view_option_value</replaceable>] [, ... ] )
ALTER VIEW [ IF EXISTS ] <replaceable class="parameter">name</replaceable> RESET ( <replaceable class="parameter">view_option_name</replaceable> [, ... ] )
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>ALTER VIEW</command> changes various auxiliary properties
   of a view.  (If you want to modify the view's defining query,
   use <command>CREATE OR REPLACE VIEW</command>.)
  </para>

  <para>
   You must own the view to use <command>ALTER VIEW</command>.
   To change a view's schema, you must also have <literal>CREATE</literal>
   privilege on the new schema.
   To alter the owner, you must be able to <literal>SET ROLE</literal> to the
   new owning role, and that role must have <literal>CREATE</literal>
   privilege on the view's schema.
   (These restrictions enforce that altering the owner
   doesn't do anything you couldn't do by dropping and recreating the view.
   However, a superuser can alter ownership of any view anyway.)
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry>
    <term><replaceable class="parameter">name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of an existing view.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">column_name</replaceable></term>
    <listitem>
     <para>
      Name of an existing column.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">new_column_name</replaceable></term>
    <listitem>
     <para>
      New name for an existing column.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>IF EXISTS</literal></term>
    <listitem>
     <para>
      Do not throw an error if the view does not exist. A notice is issued
      in this case.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>SET</literal>/<literal>DROP DEFAULT</literal></term>
    <listitem>
     <para>
      These forms set or remove the default value for a column.

Title: ALTER VIEW: Changing View Definitions
Summary
The `ALTER VIEW` command modifies auxiliary properties of a view, such as default values, ownership, renaming columns/views, and schema. It does not modify the defining query of the view; use `CREATE OR REPLACE VIEW` for that. The user must own the view and have necessary privileges to perform these operations, such as `CREATE` privilege on the new schema when changing schema or being able to `SET ROLE` to the new owning role when altering the owner. A superuser can alter ownership of any view.