Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/ref/alter_table.sgml`
aa539b5dc43d1a4f4e0a0f9837e0ad6dbf60b0b7d137e3a50000000100000fa0
 a generated column.  Existing data
      in a stored generated column is rewritten and all the future changes
      will apply the new generation expression.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-altertable-desc-drop-expression">
    <term><literal>DROP EXPRESSION [ IF EXISTS ]</literal></term>
    <listitem>
     <para>
      This form turns a stored generated column into a normal base column.
      Existing data in the columns is retained, but future changes will no
      longer apply the generation expression.
     </para>

     <para>
      This form is currently only supported for stored generated columns (not
      virtual ones).
     </para>

     <para>
      If <literal>DROP EXPRESSION IF EXISTS</literal> is specified and the
      column is not a generated column, no error is thrown.  In this case a
      notice is issued instead.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-altertable-desc-generated-identity">
    <term><literal>ADD GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY</literal></term>
    <term><literal>SET GENERATED { ALWAYS | BY DEFAULT }</literal></term>
    <term><literal>DROP IDENTITY [ IF EXISTS ]</literal></term>
    <listitem>
     <para>
      These forms change whether a column is an identity column or change the
      generation attribute of an existing identity column.
      See <link linkend="sql-createtable"><command>CREATE TABLE</command></link> for details.
      Like <literal>SET DEFAULT</literal>, these forms only affect the
      behavior of subsequent <command>INSERT</command>
      and <command>UPDATE</command> commands; they do not cause rows
      already in the table to change.
     </para>

     <para>
      If <literal>DROP IDENTITY IF EXISTS</literal> is specified and the
      column is not an identity column, no error is thrown.  In this case a
      notice is issued instead.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-altertable-desc-set-sequence-option">
    <term><literal>SET <replaceable>sequence_option</replaceable></literal></term>
    <term><literal>RESTART</literal></term>
    <listitem>
     <para>
      These forms alter the sequence that underlies an existing identity
      column.  <replaceable>sequence_option</replaceable> is an option
      supported by <link linkend="sql-altersequence"><command>ALTER SEQUENCE</command></link> such
      as <literal>INCREMENT BY</literal>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-altertable-desc-set-statistics">
    <term><literal>SET STATISTICS</literal></term>
    <listitem>
     <para>
      This form
      sets the per-column statistics-gathering target for subsequent
      <link linkend="sql-analyze"><command>ANALYZE</command></link> operations.
      The target can be set in the range 0 to 10000.  Set it
      to <literal>DEFAULT</literal> to revert to using the system default
      statistics target (<xref linkend="guc-default-statistics-target"/>).
      (Setting to a value of -1 is an obsolete way spelling to get the same
      outcome.)
      For more information on the use of statistics by the
      <productname>PostgreSQL</productname> query planner, refer to
      <xref linkend="planner-stats"/>.
     </para>
     <para>
      <literal>SET STATISTICS</literal> acquires a
      <literal>SHARE UPDATE EXCLUSIVE</literal> lock.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry id="sql-altertable-desc-set-attribute-option">
    <term><literal>SET ( <replaceable class="parameter">attribute_option</replaceable> = <replaceable class="parameter">value</replaceable> [, ... ] )</literal></term>
    <term><literal>RESET ( <replaceable class="parameter">attribute_option</replaceable> [, ... ] )</literal></term>
    <listitem>
     <para>
      This form sets or resets per-attribute options.  Currently, the only
      defined per-attribute options are <literal>n_distinct</literal> and
    

Title: ALTER TABLE: Generated Columns, Identity Columns, Sequence Options, and Statistics
Summary
This section describes ALTER TABLE options for managing generated columns (setting and dropping expressions), identity columns (adding, setting, and dropping identity properties), altering the underlying sequence of an identity column (using ALTER SEQUENCE options), and setting per-column statistics targets for ANALYZE operations. It also details how these operations affect data and subsequent INSERT/UPDATE commands.