<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_type.sgml,v 1.7 2008/11/14 10:22:45 petere Exp $
PostgreSQL documentation
-->

<refentry id="SQL-ALTERTYPE">
 <refmeta>
  <refentrytitle id="sql-altertype-title">ALTER TYPE</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>ALTER TYPE</refname>
  <refpurpose>
   change the definition of a type
  </refpurpose>
 </refnamediv>

 <indexterm zone="sql-altertype">
  <primary>ALTER TYPE</primary>
 </indexterm>

 <refsynopsisdiv>
  <synopsis>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable> 
ALTER TYPE <replaceable class="PARAMETER">name</replaceable> SET SCHEMA <replaceable class="PARAMETER">new_schema</replaceable>
  </synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>ALTER TYPE</command> changes the definition of an existing type.
  </para>

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

 <refsect1>
  <title>Parameters</title>

   <para>
    <variablelist>
     <varlistentry>
      <term><replaceable class="PARAMETER">name</replaceable></term>
      <listitem>
       <para>
        The name (possibly schema-qualified) of an existing type to
        alter.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">new_name</replaceable></term>
      <listitem>
       <para>
        The new name for the type.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">new_owner</replaceable></term>
      <listitem>
       <para>
        The user name of the new owner of the type.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="PARAMETER">new_schema</replaceable></term>
      <listitem>
       <para>
        The new schema for the type.
       </para>
      </listitem>
     </varlistentry>

    </variablelist>
   </para>
  </refsect1>

 <refsect1>
  <title>Examples</title>

  <para> 
   To rename a data type:
   <programlisting>
ALTER TYPE electronic_mail RENAME TO email;
   </programlisting>
  </para>

  <para> 
   To change the owner of the type <literal>email</literal>
   to <literal>joe</literal>:
   <programlisting>
ALTER TYPE email OWNER TO joe;
   </programlisting>
  </para>

  <para>
   To change the schema of the type <literal>email</literal>
   to <literal>customers</literal>:
   <programlisting>
ALTER TYPE email SET SCHEMA customers;
   </programlisting>
  </para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>
    
  <para>
   There is no <command>ALTER TYPE</command> statement in the SQL
   standard.
  </para>
 </refsect1>
</refentry>
