head	1.26;
access;
symbols
	REL9_0_0:1.25.2.1
	REL9_1_ALPHA1:1.26
	REL9_0_RC1:1.25.2.1
	REL9_0_BETA4:1.25.2.1
	REL9_0_STABLE:1.25.0.2
	REL9_0_BETA3:1.25
	REL9_0_BETA2:1.25
	REL7_4_29:1.6
	REL8_0_25:1.9
	REL8_1_21:1.13
	REL8_2_17:1.15
	REL8_3_11:1.19
	REL8_4_4:1.24
	REL9_0_BETA1:1.25
	REL9_0_ALPHA5_BRANCH:1.24.0.12
	REL9_0_ALPHA5:1.24
	REL7_4_28:1.6
	REL8_0_24:1.9
	REL8_1_20:1.13
	REL8_2_16:1.15
	REL8_3_10:1.19
	REL8_4_3:1.24
	REL9_0_ALPHA4:1.24
	REL9_0_ALPHA4_BRANCH:1.24.0.10
	REL8_5_ALPHA3:1.24
	REL8_5_ALPHA3_BRANCH:1.24.0.8
	REL7_4_27:1.6
	REL8_0_23:1.9
	REL8_1_19:1.13
	REL8_2_15:1.15
	REL8_3_9:1.19
	REL8_4_2:1.24
	REL8_5_ALPHA2:1.24
	REL8_5_ALPHA2_BRANCH:1.24.0.6
	REL7_4_26:1.6
	REL8_0_22:1.9
	REL8_1_18:1.13
	REL8_2_14:1.15
	REL8_3_8:1.19
	REL8_4_1:1.24
	REL8_5_ALPHA1:1.24
	REL8_5_ALPHA1_BRANCH:1.24.0.4
	REL8_4_STABLE:1.24.0.2
	REL8_4_0:1.24
	REL8_4_RC2:1.24
	REL8_4_RC1:1.24
	REL8_4_BETA2:1.24
	REL8_4_BETA1:1.24
	REL7_4_25:1.6
	REL8_0_21:1.9
	REL8_1_17:1.13
	REL8_2_13:1.15
	REL8_3_7:1.19
	REL7_4_24:1.6
	REL8_0_20:1.9
	REL8_1_16:1.13
	REL8_2_12:1.15
	REL8_3_6:1.19
	REL7_4_23:1.6
	REL8_0_19:1.9
	REL8_1_15:1.13
	REL8_2_11:1.15
	REL8_3_5:1.19
	REL7_4_22:1.6
	REL8_0_18:1.9
	REL8_1_14:1.13
	REL8_2_10:1.15
	REL8_3_4:1.19
	REL7_4_21:1.6
	REL8_0_17:1.9
	REL8_1_13:1.13
	REL8_2_9:1.15
	REL8_3_3:1.19
	REL7_4_20:1.6
	REL8_0_16:1.9
	REL8_1_12:1.13
	REL8_2_8:1.15
	REL8_3_2:1.19
	REL8_2_7:1.15
	REL8_3_1:1.19
	REL8_3_STABLE:1.19.0.2
	REL8_3_0:1.19
	REL8_3_RC2:1.19
	REL7_4_19:1.6
	REL8_0_15:1.9
	REL8_1_11:1.13
	REL8_2_6:1.15
	REL8_3_RC1:1.19
	REL8_3_BETA4:1.19
	REL8_3_BETA3:1.19
	REL8_3_BETA2:1.19
	REL8_3_BETA1:1.18
	REL7_4_18:1.6
	REL8_0_14:1.9
	REL8_1_10:1.13
	REL8_2_5:1.15
	REL7_4_17:1.6
	REL8_0_13:1.9
	REL8_1_9:1.13
	REL8_2_4:1.15
	REL8_0_12:1.9
	REL8_1_8:1.13
	REL8_2_3:1.15
	REL7_4_16:1.6
	REL8_0_11:1.9
	REL8_1_7:1.13
	REL8_2_2:1.15
	REL8_0_10:1.9
	REL8_1_6:1.13
	REL8_2_1:1.15
	REL7_4_15:1.6
	REL8_2_STABLE:1.15.0.2
	REL8_2_0:1.15
	REL8_2_RC1:1.15
	REL8_2_BETA3:1.15
	REL8_2_BETA2:1.15
	REL8_1_5:1.13
	REL8_0_9:1.9
	REL7_4_14:1.6
	REL8_2_BETA1:1.15
	REL7_4_13:1.6
	REL8_0_8:1.9
	REL8_1_4:1.13
	REL7_4_12:1.6
	REL8_0_7:1.9
	REL8_1_3:1.13
	REL7_4_11:1.6
	REL8_0_6:1.9
	REL8_1_2:1.13
	REL7_4_10:1.6
	REL8_0_5:1.9
	REL8_1_1:1.13
	REL8_1_STABLE:1.13.0.2
	REL8_1_0:1.13
	REL8_1_0RC1:1.12
	REL8_1_0BETA4:1.12
	REL8_1_0BETA3:1.11
	REL7_4_9:1.6
	REL8_0_4:1.9
	REL8_1_0BETA2:1.11
	REL8_1_0BETA1:1.10
	REL7_4_8:1.6
	REL8_0_3:1.9
	REL8_0_2:1.9
	REL7_4_7:1.6
	REL8_0_1:1.9
	REL8_0_STABLE:1.9.0.4
	REL8_0_0:1.9.0.2
	REL8_0_0RC5:1.9
	REL8_0_0RC4:1.9
	REL8_0_0RC3:1.9
	REL8_0_0RC2:1.9
	REL8_0_0RC1:1.9
	REL8_0_0BETA5:1.8
	REL8_0_0BETA4:1.8
	REL7_4_6:1.6
	REL8_0_0BETA3:1.8
	REL8_0_0BETA2:1.8
	REL7_4_5:1.6
	REL7_4_4:1.6
	REL8_0_0BETA1:1.7
	REL7_4_3:1.6
	REL7_4_2:1.6
	REL7_4_1:1.6
	REL7_4:1.6
	REL7_4_RC2:1.6
	REL7_4_STABLE:1.6.0.2
	REL7_4_RC1:1.6
	REL7_4_BETA5:1.5
	REL7_4_BETA4:1.5
	REL7_4_BETA3:1.4
	REL7_4_BETA2:1.2
	WIN32_DEV:1.2.0.2
	REL7_4_BETA1:1.2;
locks; strict;
comment	@# @;


1.26
date	2010.07.29.19.34.40;	author petere;	state Exp;
branches;
next	1.25;

1.25
date	2010.04.03.07.22.57;	author petere;	state Exp;
branches
	1.25.2.1;
next	1.24;

1.24
date	2008.11.14.10.22.45;	author petere;	state Exp;
branches;
next	1.23;

1.23
date	2008.11.12.15.53.34;	author petere;	state Exp;
branches;
next	1.22;

1.22
date	2008.06.15.01.25.53;	author tgl;	state Exp;
branches;
next	1.21;

1.21
date	2008.05.17.01.20.39;	author tgl;	state Exp;
branches;
next	1.20;

1.20
date	2008.05.16.23.36.04;	author tgl;	state Exp;
branches;
next	1.19;

1.19
date	2007.10.25.18.54.03;	author tgl;	state Exp;
branches;
next	1.18;

1.18
date	2007.10.03.16.48.43;	author tgl;	state Exp;
branches;
next	1.17;

1.17
date	2007.07.03.01.30.35;	author neilc;	state Exp;
branches;
next	1.16;

1.16
date	2007.01.31.23.26.02;	author momjian;	state Exp;
branches;
next	1.15;

1.15
date	2006.09.16.00.30.16;	author momjian;	state Exp;
branches;
next	1.14;

1.14
date	2006.08.21.00.57.24;	author tgl;	state Exp;
branches;
next	1.13;

1.13
date	2005.11.01.21.09.50;	author tgl;	state Exp;
branches;
next	1.12;

1.12
date	2005.10.15.20.12.33;	author neilc;	state Exp;
branches;
next	1.11;

1.11
date	2005.09.13.15.24.57;	author neilc;	state Exp;
branches;
next	1.10;

1.10
date	2005.08.01.16.11.14;	author tgl;	state Exp;
branches;
next	1.9;

1.9
date	2004.11.27.21.27.07;	author petere;	state Exp;
branches;
next	1.8;

1.8
date	2004.08.24.00.06.51;	author neilc;	state Exp;
branches;
next	1.7;

1.7
date	2003.11.29.19.51.38;	author pgsql;	state Exp;
branches;
next	1.6;

1.6
date	2003.11.01.01.56.29;	author petere;	state Exp;
branches;
next	1.5;

1.5
date	2003.09.22.00.16.57;	author petere;	state Exp;
branches;
next	1.4;

1.4
date	2003.09.09.18.28.52;	author tgl;	state Exp;
branches;
next	1.3;

1.3
date	2003.08.31.17.32.21;	author petere;	state Exp;
branches;
next	1.2;

1.2
date	2003.06.12.07.49.43;	author momjian;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	2003.03.20.07.02.07;	author momjian;	state Exp;
branches;
next	;

1.2.2.1
date	2003.09.07.04.36.44;	author momjian;	state Exp;
branches;
next	;

1.25.2.1
date	2010.07.29.19.34.37;	author petere;	state Exp;
branches;
next	;


desc
@@


1.26
log
@Fix indentation of verbatim block elements

Block elements with verbatim formatting (literallayout, programlisting,
screen, synopsis) should be aligned at column 0 independent of the surrounding
SGML, because whitespace is significant, and indenting them creates erratic
whitespace in the output.  The CSS stylesheets already take care of indenting
the output.

Assorted markup improvements to go along with it.
@
text
@<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.25 2010/04/03 07:22:57 petere Exp $
PostgreSQL documentation
-->

<refentry id="SQL-ALTERSEQUENCE">
 <refmeta>
  <refentrytitle>ALTER SEQUENCE</refentrytitle>
  <manvolnum>7</manvolnum>
  <refmiscinfo>SQL - Language Statements</refmiscinfo>
 </refmeta>

 <refnamediv>
  <refname>ALTER SEQUENCE</refname>
  <refpurpose>
   change the definition of a sequence generator
  </refpurpose>
 </refnamediv> 

 <indexterm zone="sql-altersequence">
  <primary>ALTER SEQUENCE</primary>
 </indexterm>

 <refsynopsisdiv>
<synopsis>
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
    [ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE ] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE ]
    [ START [ WITH ] <replaceable class="parameter">start</replaceable> ]
    [ RESTART [ [ WITH ] <replaceable class="parameter">restart</replaceable> ] ]
    [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
    [ OWNED BY { <replaceable class="parameter">table</replaceable>.<replaceable class="parameter">column</replaceable> | NONE } ]
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
</synopsis>
 </refsynopsisdiv>

 <refsect1>
  <title>Description</title>

  <para>
   <command>ALTER SEQUENCE</command> changes the parameters of an existing
   sequence generator.  Any parameters not specifically set in the
   <command>ALTER SEQUENCE</command> command retain their prior settings.
  </para>

  <para>
   You must own the sequence to use <command>ALTER SEQUENCE</>.
   To change a sequence's schema, you must also have <literal>CREATE</>
   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 sequence's schema.  (These restrictions enforce that altering the owner
   doesn't do anything you couldn't do by dropping and recreating the sequence.
   However, a superuser can alter ownership of any sequence anyway.)
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

   <para>
    <variablelist>
     <varlistentry>
      <term><replaceable class="parameter">name</replaceable></term>
      <listitem>
       <para>
        The name (optionally schema-qualified) of a sequence to be altered.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">increment</replaceable></term>
      <listitem>
       <para>
        The clause <literal>INCREMENT BY <replaceable
        class="parameter">increment</replaceable></literal> is
        optional. A positive value will make an ascending sequence, a
        negative one a descending sequence.  If unspecified, the old
        increment value will be maintained.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">minvalue</replaceable></term>
      <term><literal>NO MINVALUE</literal></term>
      <listitem>
       <para>
        The optional clause <literal>MINVALUE <replaceable
        class="parameter">minvalue</replaceable></literal> determines
        the minimum value a sequence can generate. If <literal>NO
        MINVALUE</literal> is specified, the defaults of 1 and
        -2<superscript>63</>-1 for ascending and descending sequences,
        respectively, will be used.  If neither option is specified,
        the current minimum value will be maintained.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">maxvalue</replaceable></term>
      <term><literal>NO MAXVALUE</literal></term>
      <listitem>
       <para>
        The optional clause <literal>MAXVALUE <replaceable
        class="parameter">maxvalue</replaceable></literal> determines
        the maximum value for the sequence. If <literal>NO
        MAXVALUE</literal> is specified, the defaults are
        2<superscript>63</>-1 and -1 for ascending and descending
        sequences, respectively, will be used.  If neither option is
        specified, the current maximum value will be maintained.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">start</replaceable></term>
      <listitem>
       <para>
        The optional clause <literal>START WITH <replaceable
        class="parameter">start</replaceable></literal> changes the
        recorded start value of the sequence.  This has no effect on the
        <emphasis>current</> sequence value; it simply sets the value
        that future <command>ALTER SEQUENCE RESTART</> commands will use.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">restart</replaceable></term>
      <listitem>
       <para>
        The optional clause <literal>RESTART [ WITH <replaceable
        class="parameter">restart</replaceable> ]</literal> changes the
        current value of the sequence.  This is equivalent to calling the
        <function>setval</> function with <literal>is_called</literal> =
        <literal>false</>: the specified value will be returned by the
        <emphasis>next</> call of <function>nextval</>.
        Writing <literal>RESTART</> with no <replaceable
        class="parameter">restart</> value is equivalent to supplying
        the start value that was recorded by <command>CREATE SEQUENCE</>
        or last set by <command>ALTER SEQUENCE START WITH</>.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><replaceable class="parameter">cache</replaceable></term>
      <listitem>
       <para>
        The clause <literal>CACHE <replaceable
        class="parameter">cache</replaceable></literal> enables
        sequence numbers to be preallocated and stored in memory for
        faster access. The minimum value is 1 (only one value can be
        generated at a time, i.e., no cache).  If unspecified, the old
        cache value will be maintained.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><literal>CYCLE</literal></term>
      <listitem>
       <para>
        The optional <literal>CYCLE</literal> key word can be used to enable
        the sequence to wrap around when the
        <replaceable class="parameter">maxvalue</replaceable> or
        <replaceable class="parameter">minvalue</replaceable> has been
        reached by
        an ascending or descending sequence respectively. If the limit is
        reached, the next number generated will be the
        <replaceable class="parameter">minvalue</replaceable> or
        <replaceable class="parameter">maxvalue</replaceable>,
        respectively.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><literal>NO CYCLE</literal></term>
      <listitem>
       <para>
        If the optional <literal>NO CYCLE</literal> key word is
        specified, any calls to <function>nextval</function> after the
        sequence has reached its maximum value will return an error.
        If neither <literal>CYCLE</literal> or <literal>NO
        CYCLE</literal> are specified, the old cycle behavior will be
        maintained.
       </para>
      </listitem>
     </varlistentry>

   <varlistentry>
    <term><literal>OWNED BY</literal> <replaceable class="parameter">table</replaceable>.<replaceable class="parameter">column</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</>.
     </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>
   To avoid blocking of concurrent transactions that obtain numbers from the
   same sequence, <command>ALTER SEQUENCE</command>'s effects on the sequence
   generation parameters are never rolled back; those changes take effect
   immediately and are not reversible.  However, the <literal>OWNED BY</>,
   <literal>OWNER TO</>, <literal>RENAME TO</>, and <literal>SET SCHEMA</>
   clauses cause ordinary catalog updates that can be rolled back.
  </para>

  <para>
   <command>ALTER SEQUENCE</command> will not immediately affect
   <function>nextval</> 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</>
   status for the sequence.  (Before <productname>PostgreSQL</productname>
   8.3, it sometimes did.)
  </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>START WITH</>,
   <literal>OWNED BY</>, <literal>OWNER TO</>, <literal>RENAME TO</>, 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>
@


1.25
log
@Remove unnecessary xref endterm attributes and title ids

The endterm attribute is mainly useful when the toolchain does not support
automatic link target text generation for a particular situation.  In  the
past, this was required by the man page tools for all reference page links,
but that is no longer the case, and it now actually gets in the way of
proper automatic link text generation.  The only remaining use cases are
currently xrefs to refsects.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.24 2008/11/14 10:22:45 petere Exp $
d25 1
a25 1
  <synopsis>
d35 1
a35 1
  </synopsis>
@


1.25.2.1
log
@Fix indentation of verbatim block elements

Block elements with verbatim formatting (literallayout, programlisting,
screen, synopsis) should be aligned at column 0 independent of the surrounding
SGML, because whitespace is significant, and indenting them creates erratic
whitespace in the output.  The CSS stylesheets already take care of indenting
the output.

Assorted markup improvements to go along with it.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.25 2010/04/03 07:22:57 petere Exp $
d25 1
a25 1
<synopsis>
d35 1
a35 1
</synopsis>
@


1.24
log
@Set SQL man pages to be section 7 by default, and only transform them to
another section if required by the platform (instead of the old way of
building them in section "l" and always transforming them to the
platform-specific section).

This speeds up the installation on common platforms, and it avoids some
funny business with the man page tools and build process.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.23 2008/11/12 15:53:34 petere Exp $
d8 1
a8 1
  <refentrytitle id="SQL-ALTERSEQUENCE-TITLE">ALTER SEQUENCE</refentrytitle>
d305 2
a306 2
   <member><xref linkend="sql-createsequence" endterm="sql-createsequence-title"></member>
   <member><xref linkend="sql-dropsequence" endterm="sql-dropsequence-title"></member>
@


1.23
log
@Remove unnecessary whitespace in refname elements.  This confuses the
man page tools.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.22 2008/06/15 01:25:53 tgl Exp $
d9 1
@


1.22
log
@Rearrange ALTER TABLE syntax processing as per my recent proposal: the
grammar allows ALTER TABLE/INDEX/SEQUENCE/VIEW interchangeably for all
subforms of those commands, and then we sort out what's really legal
at execution time.  This allows the ALTER SEQUENCE/VIEW reference pages
to fully document all the ALTER forms available for sequences and views
respectively, and eliminates a longstanding cause of confusion for users.

The net effect is that the following forms are allowed that weren't before:
	ALTER SEQUENCE OWNER TO
	ALTER VIEW ALTER COLUMN SET/DROP DEFAULT
	ALTER VIEW OWNER TO
	ALTER VIEW SET SCHEMA
(There's no actual functionality gain here, but formerly you had to say
ALTER TABLE instead.)

Interestingly, the grammar tables actually get smaller, probably because
there are fewer special cases to keep track of.

I did not disallow using ALTER TABLE for these operations.  Perhaps we
should, but there's a backwards-compatibility issue if we do; in fact
it would break existing pg_dump scripts.  I did however tighten up
ALTER SEQUENCE and ALTER VIEW to reject non-sequences and non-views
in the new cases as well as a couple of cases where they didn't before.

The patch doesn't change pg_dump to use the new syntaxes, either.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.21 2008/05/17 01:20:39 tgl Exp $
d13 1
a13 3
  <refname>
   ALTER SEQUENCE
  </refname>
@


1.21
log
@Allow ALTER SEQUENCE START WITH to change the recorded start_value of a
sequence.  This seems an obvious extension to the recent patch, and it
makes the code noticeably cleaner and more orthogonal.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.20 2008/05/16 23:36:04 tgl Exp $
d33 1
d52 5
d215 9
d251 3
a253 3
   generation parameters are never rolled back;
   those changes take effect immediately and are not reversible.  However,
   the <literal>OWNED BY</>, <literal>RENAME</>, and <literal>SET SCHEMA</>
d273 3
a275 3
   Some variants of <command>ALTER TABLE</command> can be used with
   sequences as well; for example, to rename a sequence it is also
   possible to use <command>ALTER TABLE RENAME</command>.
d296 1
a296 1
   <literal>OWNED BY</>, <literal>RENAME</>, and
@


1.20
log
@Add a RESTART (without parameter) option to ALTER SEQUENCE, allowing a
sequence to be reset to its original starting value.  This requires adding the
original start value to the set of parameters (columns) of a sequence object,
which is a user-visible change with potential compatibility implications;
it also forces initdb.

Also add hopefully-SQL-compatible RESTART/CONTINUE IDENTITY options to
TRUNCATE TABLE.  RESTART IDENTITY executes ALTER SEQUENCE RESTART for all
sequences "owned by" any of the truncated relations.  CONTINUE IDENTITY is
a no-op option.

Zoltan Boszormenyi
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.19 2007/10/25 18:54:03 tgl Exp $
d29 3
a31 1
    [ RESTART [ [ WITH ] <replaceable class="parameter">start</replaceable> ] ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
d117 13
d131 1
a131 1
        class="parameter">start</replaceable> ]</literal> changes the
d137 3
a139 2
        class="parameter">start</replaceable> value is equivalent to supplying
        the start value used when the sequence was created.
d280 2
a281 1
   standard, except for the <literal>OWNED BY</>, <literal>RENAME</>, and
@


1.19
log
@Fix ALTER SEQUENCE so that it does not affect the value of currval() for
the sequence.  Also, make setval() with is_called = false not affect the
currval state, either.  Per report from Kris Jurka that an implicit
ALTER SEQUENCE OWNED BY unexpectedly caused currval() to become valid.
Since this isn't 100% backwards compatible, it will go into HEAD only;
I'll put a more limited patch into 8.2.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.18 2007/10/03 16:48:43 tgl Exp $
d29 1
a29 1
    [ RESTART [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
d115 2
a116 2
        The optional clause <literal>RESTART WITH <replaceable
        class="parameter">start</replaceable></literal> changes the
d121 3
@


1.18
log
@Some editorial improvements for recently-added ALTER SEQUENCE/VIEW
documentation.  Heikki and Tom
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.17 2007/07/03 01:30:35 neilc Exp $
d117 4
a120 1
        current value of the sequence.
d233 6
@


1.17
log
@Add ALTER VIEW ... RENAME TO, and a RENAME TO clause to ALTER SEQUENCE.
Sequences and views could previously be renamed using ALTER TABLE, but
this was a repeated source of confusion for users. Update the docs,
and psql tab completion. Patch from David Fetter; various minor fixes
by myself.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.16 2007/01/31 23:26:02 momjian Exp $
d31 1
a32 1
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> RENAME TO <replaceable class="parameter">new_name</replaceable>
d187 1
a187 1
    <term><replaceable class="parameter">new_schema</replaceable></term>
d190 1
a190 1
      The new schema for the sequence.
d196 1
a196 1
    <term><replaceable class="parameter">new_name</replaceable></term>
d199 1
a199 1
      The new name for the sequence.
a208 11
  <title>Examples</title>

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

 <refsect1>
d216 2
a217 2
   the <literal>OWNED BY</> and <literal>SET SCHEMA</> clauses are ordinary
   catalog updates and can be rolled back.
d231 2
a232 2
   sequences as well; for example, to rename a sequence use <command>ALTER
   TABLE RENAME</command>.
d236 10
d252 3
a254 3
   standard,
   except for the <literal>OWNED BY</> and <literal>SET SCHEMA</literal>
   clauses, which are <productname>PostgreSQL</productname> extensions.
@


1.16
log
@Update reference documentation on may/can/might:

Standard English uses "may", "can", and "might" in different ways:

        may - permission, "You may borrow my rake."

        can - ability, "I can lift that log."

        might - possibility, "It might rain today."

Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice.  Similarly, "It may crash" is better stated, "It might crash".
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.15 2006/09/16 00:30:16 momjian Exp $
d32 1
d186 18
a203 8
     <varlistentry>
      <term><replaceable class="parameter">new_schema</replaceable></term>
      <listitem>
       <para>
        The new schema for the sequence.
       </para>
      </listitem>
     </varlistentry>
@


1.15
log
@Remove emacs info from footer of SGML files.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.14 2006/08/21 00:57:24 tgl Exp $
d139 1
a139 1
        The optional <literal>CYCLE</literal> key word may be used to enable
@


1.14
log
@Fix all known problems with pg_dump's handling of serial sequences
by abandoning the idea that it should say SERIAL in the dump.  Instead,
dump serial sequences and column defaults just like regular ones.
Add a new backend command ALTER SEQUENCE OWNED BY to let pg_dump recreate
the sequence-to-column dependency that was formerly created "behind the
scenes" by SERIAL.  This restores SERIAL to being truly "just a macro"
consisting of component operations that can be stated explicitly in SQL.
Furthermore, the new command allows sequence ownership to be reassigned,
so that old mistakes can be cleaned up.

Also, downgrade the OWNED-BY dependency from INTERNAL to AUTO, since there
is no longer any very compelling argument why the sequence couldn't be
dropped while keeping the column.  (This forces initdb, to be sure the
right kinds of dependencies are in there.)

Along the way, add checks to prevent ALTER OWNER or SET SCHEMA on an
owned sequence; you can now only do this indirectly by changing the
owning table's owner or schema.  This is an oversight in previous
releases, but probably not worth back-patching.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.13 2005/11/01 21:09:50 tgl Exp $
a257 17

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
@


1.13
log
@Make an editorial pass over the reference pages.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.12 2005/10/15 20:12:33 neilc Exp $
d30 1
d167 18
d213 5
a217 2
   same sequence, <command>ALTER SEQUENCE</command> is never rolled back;
   the changes take effect immediately and are not reversible.
d225 2
a226 1
   sequence parameters.  The current backend will be affected immediately.
d243 2
a244 2
   except for the <literal>SET SCHEMA</literal> variant, which is a
   <productname>PostgreSQL</productname> extension.
d247 10
@


1.12
log
@Fix assorted typos in the documentation, and use American spelling
rather than British. Patch from Michael Fuhr.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.11 2005/09/13 15:24:57 neilc Exp $
d218 2
a219 1
   <command>ALTER SEQUENCE</command> conforms with <acronym>SQL:2003</acronym>,
@


1.11
log
@Minor SGML markup fixes.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.10 2005/08/01 16:11:14 tgl Exp $
d160 1
a160 1
        CYCLE</literal> are specified, the old cycle behaviour will be
@


1.10
log
@Documentation for ALTER object SET SCHEMA commands.  Also some minor
editorialization.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.9 2004/11/27 21:27:07 petere Exp $
d135 1
a135 1
      <term>CYCLE</term>
d153 1
a153 1
      <term>NO CYCLE</term>
d200 1
a200 1
   <literal>nextval</> results in backends,
@


1.9
log
@Update of conformance information to SQL:2003
by Troels Arvin, Simon Riggs, Elein Mustain

Make spelling of SQL standard names uniform.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.8 2004/08/24 00:06:51 neilc Exp $
d30 1
d39 8
a46 2
   sequence generator.  Any parameter not specifically set in the
   <command>ALTER SEQUENCE</command> command retains its prior setting.
d165 9
d205 6
d218 3
a220 1
   <command>ALTER SEQUENCE</command> conforms with <acronym>SQL:2003</acronym>.
@


1.8
log
@Various minor improvements to the SGML documentation: fix some incorrect
SGML markup, add a "deprecated features" section to the 8.0 release
notes, untabify release.sgml and runtime.sgml, and make some other
minor improvements.
@
text
@d2 1
a2 1
$PostgreSQL: pgsql-server/doc/src/sgml/ref/alter_sequence.sgml,v 1.7 2003/11/29 19:51:38 pgsql Exp $
d193 1
a193 8
  <title>
   Compatibility
  </title>

  <refsect2>
   <title>
    SQL99
   </title>
d195 3
a197 7
   <para>
    <command>ALTER SEQUENCE</command> is a <productname>PostgreSQL</productname>
    language extension.
    There is no <command>ALTER SEQUENCE</command> statement
    in <acronym>SQL99</acronym>.
   </para>
  </refsect2>
@


1.7
log
@
$Header: -> $PostgreSQL Changes ...
@
text
@d2 1
a2 1
$PostgreSQL: /cvsroot/pgsql-server/doc/src/sgml/ref/alter_sequence.sgml,v 1.6 2003/11/01 01:56:29 petere Exp $
d17 1
a17 1
   alter the definition of a sequence generator
@


1.6
log
@Spell checking, consistent terminology.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/alter_sequence.sgml,v 1.5 2003/09/22 00:16:57 petere Exp $
@


1.5
log
@Make the SQL command synopses appear less random.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/alter_sequence.sgml,v 1.4 2003/09/09 18:28:52 tgl Exp $
d52 1
a52 1
	The name (optionally schema-qualified) of a sequence to be altered.
d61 5
a65 5
	The
	<option>INCREMENT BY <replaceable class="parameter">increment</replaceable></option>
	clause is optional. A positive value will make an
	ascending sequence, a negative one a descending sequence.
	If unspecified, the old increment value will be maintained.
d72 1
a72 1
      <term>NO MINVALUE</term>
d75 7
a81 6
	The optional clause <option>MINVALUE
	 <replaceable class="parameter">minvalue</replaceable></option>
	determines the minimum value
	a sequence can generate. If <option>NO MINVALUE</option> is specified,
    the defaults of 1 and -2^63-1 for ascending and descending sequences, respectively, will be used.  If neither option is specified, the current minimum
    value will be maintained.
d88 1
a88 1
      <term>NO MAXVALUE</term>
d91 7
a97 7
	The optional clause <option>MAXVALUE
	 <replaceable class="parameter">maxvalue</replaceable></option>
	determines the maximum value for the sequence. If 
    <option>NO MAXVALUE</option> is specified, the defaults are 2^63-1 and -1 for
	ascending and descending sequences, respectively, will be used.  If
    neither option is specified, the current maximum value will be
    maintained.
d106 3
a108 3
	The optional <option>RESTART WITH
	 <replaceable class="parameter">start</replaceable></option>
	 clause changes the current value of the sequence.
d117 6
a122 5
	The <option>CACHE <replaceable class="parameter">cache</replaceable></option> option
	enables sequence numbers to be preallocated
	and stored in memory for faster access. The  minimum
	value is 1 (only one value can be generated at a time, i.e., no cache).
	If unspecified, the old cache value will be maintained.
d131 10
a140 10
	The optional <option>CYCLE</option> keyword may be used to enable
	the sequence to wrap around when the
	<replaceable class="parameter">maxvalue</replaceable> or
	<replaceable class="parameter">minvalue</replaceable> has been
	reached by
	an ascending or descending sequence respectively. If the limit is
	reached, the next number generated will be the
	<replaceable class="parameter">minvalue</replaceable> or
	<replaceable class="parameter">maxvalue</replaceable>,
	respectively.
d145 13
a157 12
	 <varlistentry>
	  <term>NO CYCLE</term>
	  <listitem>
	   <para>
	If the optional <option>NO CYCLE</option> keyword is specified, any
	calls to <function>nextval</function> after the sequence has reached
	its maximum value will return an error.  If neither
	<option>CYCLE</option> or <option>NO CYCLE</option> are specified,
	the old cycle behaviour will be maintained.
	   </para>
	  </listitem>
	</varlistentry>
d167 3
a170 3
  <programlisting>
ALTER SEQUENCE serial RESTART WITH 105;
  </programlisting>
@


1.4
log
@Remove a bunch of content-free Diagnostics sections, as per previous
discussion.  (Still have some work to do editing the remainder.)
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/alter_sequence.sgml,v 1.3 2003/08/31 17:32:21 petere Exp $
d27 1
a27 1
ALTER SEQUENCE <replaceable class="parameter">seqname</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
d49 1
a49 1
      <term><replaceable class="parameter">seqname</replaceable></term>
@


1.3
log
@Add/edit index entries.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/alter_sequence.sgml,v 1.2 2003/06/12 07:49:43 momjian Exp $
a25 3
  <refsynopsisdivinfo>
   <date>1999-07-20</date>
  </refsynopsisdivinfo>
d31 15
a45 8
  
  <refsect2 id="R2-SQL-ALTERSEQUENCE-1">
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
   <title>
    Inputs
   </title>
a46 1

d106 2
a107 2
	 <replaceable class="parameter">start</replaceable>
	 clause</option> enables the sequence to re-begin anywhere.
d157 1
a157 56
  </refsect2>

  <refsect2 id="R2-SQL-ALTERSEQUENCE-2">
   <refsect2info>
    <date>1998-09-11</date>
   </refsect2info>
   <title>
    Outputs
   </title>
   <para>

    <variablelist>
     <varlistentry>
      <term><computeroutput>
ALTER SEQUENCE
       </computeroutput></term>
      <listitem>
       <para>
	Message returned if the command is successful.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term><computeroutput>
ERROR:  AlterSequence: MINVALUE (<replaceable class="parameter">start</replaceable>) can't be >= MAXVALUE (<replaceable class="parameter">max</replaceable>)
       </computeroutput></term>
      <listitem>
       <para>
	If the specified starting value is out of range.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term><computeroutput>
ERROR:  AlterSequence: START value (<replaceable class="parameter">start</replaceable>) can't be < MINVALUE (<replaceable class="parameter">min</replaceable>)
       </computeroutput></term>
      <listitem>
       <para>
	If the specified starting value is out of range.
       </para>
      </listitem>
     </varlistentry>
     <varlistentry>
      <term><computeroutput>
ERROR:  AlterSequence: MINVALUE (<replaceable class="parameter">min</replaceable>) can't be >= MAXVALUE (<replaceable class="parameter">max</replaceable>)
       </computeroutput></term>
      <listitem>
       <para>
	If the minimum and maximum values are inconsistent.
       </para>
      </listitem>
     </varlistentry>
    </variablelist>
   </para>
  </refsect2>
 </refsynopsisdiv>
d159 2
a160 4
 <refsect1 id="R1-SQL-ALTERSEQUENCE-1">
  <title>
   Description
  </title>
a162 10
   See <xref linkend="SQL-CREATESEQUENCE"> for limitations, and uses
   of sequences.
  </para>
 </refsect1>

 <refsect1 id="R1-SQL-ALTERSEQUENCE-2">
  <title>
   Usage
  </title>
  <para>
d170 3
a172 4
 <refsect1 id="R1-SQL-ALTERSEQUENCE-5">
  <title>
   Notes
  </title>
d174 3
a176 5
   To avoid blocking of concurrent transactions that obtain numbers from the same
   sequence, a nextval operation is never rolled back; that is, once a value has 
   been fetched it is considered used, even if the transaction that did the nextval
   later aborts. This means that aborted transactions may leave unused "holes" in
   the sequence of assigned values. setval operations are never rolled back, either.
d178 1
d180 5
a184 4
   <command>ALTER SEQUENCE</command> will not immediately affect backends, other than the
   current one, which have cached sequence values. They must use up all cached values
   prior to noticing the changed sequence parameters.  The current backend will be 
   immediatly affected.
d189 1
a189 1
 <refsect1 id="R1-SQL-ALTERSEQUENCE-3">
d194 1
a194 4
  <refsect2 id="R2-SQL-ALTERSEQUENCE-4">
   <refsect2info>
    <date>2003-03-02</date>
   </refsect2info>
@


1.2
log
@Brief note about sequence cache not being cleared in other backends.

Actually clear the cache in the backend making the alteration.  This
follows in the footsteps of setval().

Rod Taylor
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/alter_sequence.sgml,v 1.1 2003/03/20 07:02:07 momjian Exp $
d11 1
d20 5
@


1.2.2.1
log
@Update this branch to match CVS head, includes WIN32 improvements.
@
text
@d2 1
a2 1
$Header: /cvsroot/pgsql-server/doc/src/sgml/ref/alter_sequence.sgml,v 1.3 2003/08/31 17:32:21 petere Exp $
a10 1

a18 5

 <indexterm zone="sql-altersequence">
  <primary>ALTER SEQUENCE</primary>
 </indexterm>

@


1.1
log
@Todo items:
Add ALTER SEQUENCE to modify min/max/increment/cache/cycle values

Also updated create sequence docs to mention NO MINVALUE, & NO MAXVALUE.

New Files:
doc/src/sgml/ref/alter_sequence.sgml
src/test/regress/expected/sequence.out
src/test/regress/sql/sequence.sql


ALTER SEQUENCE is NOT transactional.  It behaves similarly to setval().
It matches the proposed SQL200N spec, as well as Oracle in most ways --
Oracle lacks RESTART WITH for some strange reason.

--
Rod Taylor <rbt@@rbt.ca>
@
text
@d2 1
a2 1
$Header: /projects/cvsroot/pgsql-server/doc/src/sgml/ref/create_sequence.sgml,v 1.30 2003/01/19 00:13:29 momjian Exp $
d238 6
@

