Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/ref/alter_foreign_table.sgml`
b6e1a6e7c0db4cf92a36662ee9c52cdc2370889ca036a1500000000100000fd2
 <literal>ADD</literal> is assumed
      if no operation is explicitly specified.  Duplicate option names are not
      allowed (although it's OK for a table option and a column option to have
      the same name).  Option names and values are also validated using the
      foreign data wrapper library.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>RENAME</literal></term>
    <listitem>
     <para>
      The <literal>RENAME</literal> forms change the name of a foreign table
      or the name of an individual column in a foreign table.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>SET SCHEMA</literal></term>
    <listitem>
     <para>
      This form moves the foreign table into another schema.
     </para>
    </listitem>
   </varlistentry>

  </variablelist>
  </para>

  <para>
   All the actions except <literal>RENAME</literal> and <literal>SET SCHEMA</literal>
   can be combined into
   a list of multiple alterations to apply in parallel.  For example, it
   is possible to add several columns and/or alter the type of several
   columns in a single command.
  </para>

  <para>
   If the command is written as <literal>ALTER FOREIGN TABLE IF EXISTS ...</literal>
   and the foreign table does not exist, no error is thrown. A notice is
   issued in this case.
  </para>

  <para>
   You must own the table to use <command>ALTER FOREIGN TABLE</command>.
   To change the schema of a foreign table, 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 table's schema.  (These restrictions enforce that altering the owner
   doesn't do anything you couldn't do by dropping and recreating the table.
   However, a superuser can alter ownership of any table anyway.)
   To add a column or alter a column type, you must also
   have <literal>USAGE</literal> privilege on the data type.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

    <variablelist>

     <varlistentry>
      <term><replaceable class="parameter">name</replaceable></term>
      <listitem>
       <para>
        The name (possibly schema-qualified) of an existing foreign table to
        alter. If <literal>ONLY</literal> is specified before the table name, only
        that table is altered. If <literal>ONLY</literal> is not specified, the table
        and all its descendant tables (if any) are altered.  Optionally,
        <literal>*</literal> can be specified after the table name to explicitly
        indicate that descendant tables are included.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">column_name</replaceable></term>
      <listitem>
       <para>
        Name of a new or 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><replaceable class="parameter">new_name</replaceable></term>
      <listitem>
       <para>
        New name for the table.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">data_type</replaceable></term>
      <listitem>
       <para>
        Data type of the new column, or new data type for an existing
        column.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">table_constraint</replaceable></term>
      <listitem>
       <para>
        New table constraint for the foreign table.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">constraint_name</replaceable></term>

Title: ALTER FOREIGN TABLE: Combining Actions, Error Handling, Permissions, and Parameters
Summary
This section elaborates on the ALTER FOREIGN TABLE command. It details how multiple actions (excluding RENAME and SET SCHEMA) can be combined. It explains the behavior of 'IF EXISTS' and describes the necessary ownership and privileges (CREATE, SET ROLE, USAGE) for different operations. It further defines the parameters used within the ALTER FOREIGN TABLE command, such as table names, column names, new names, data types, and constraint names.