Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/ref/alter_sequence.sgml`
4dbb816a6585bb0eff4ab62c1304e41e0b5c05f2a20b0b550000000100000d71
 class="parameter">table_name</replaceable>.<replaceable class="parameter">column_name</replaceable></term>
    <term><literal>OWNED BY NONE</literal></term>
    <listitem>
     <para>
      The <literal>OWNED BY</literal> option causes the sequence to be
      associated with a specific table column, such that if that column
      (or its whole table) is dropped, the sequence will be automatically
      dropped as well.  If specified, this association replaces any
      previously specified association for the sequence.  The specified
      table must have the same owner and be in the same schema as the
      sequence.
      Specifying <literal>OWNED BY NONE</literal> removes any existing
      association, making the sequence <quote>free-standing</quote>.
     </para>
    </listitem>
   </varlistentry>

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

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

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

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

 <refsect1>
  <title>Notes</title>

  <para>
   <command>ALTER SEQUENCE</command> will not immediately affect
   <function>nextval</function> results in backends,
   other than the current one, that have preallocated (cached) sequence
   values. They will use up all cached values prior to noticing the changed
   sequence generation parameters.  The current backend will be affected
   immediately.
  </para>

  <para>
   <command>ALTER SEQUENCE</command> does not affect the <function>currval</function>
   status for the sequence.  (Before <productname>PostgreSQL</productname>
   8.3, it sometimes did.)
  </para>

  <para>
   <command>ALTER SEQUENCE</command> blocks
   concurrent <function>nextval</function>, <function>currval</function>,
   <function>lastval</function>, and <command>setval</command> calls.
  </para>

  <para>
   For historical reasons, <command>ALTER TABLE</command> can be used with
   sequences too; but the only variants of <command>ALTER TABLE</command>
   that are allowed with sequences are equivalent to the forms shown above.
  </para>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   Restart a sequence called <literal>serial</literal>, at 105:
<programlisting>
ALTER SEQUENCE serial RESTART WITH 105;
</programlisting></para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   <command>ALTER SEQUENCE</command> conforms to the <acronym>SQL</acronym>
   standard, except for the <literal>AS</literal>, <literal>START WITH</literal>,
   <literal>OWNED BY</literal>, <literal>OWNER TO</literal>, <literal>RENAME TO</literal>, and
   <literal>SET SCHEMA</literal> clauses, which are
   <productname>PostgreSQL</productname> extensions.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-createsequence"/></member>
   <member><xref linkend="sql-dropsequence"/></member>
  </simplelist>
 </refsect1>

</refentry>

Title: ALTER SEQUENCE Parameters (Continued), Notes, Examples, and Compatibility
Summary
This section continues describing the parameters for ALTER SEQUENCE, including OWNED BY for associating a sequence with a table column, renaming the sequence's owner, changing the sequence's name, and moving the sequence to a different schema. It also includes important notes about how ALTER SEQUENCE affects cached values and blocks concurrent calls, an example of restarting a sequence, and compatibility with the SQL standard.