2003-03-20 08:02:11 +01:00
|
|
|
<!--
|
2005-09-13 17:24:57 +02:00
|
|
|
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_sequence.sgml,v 1.11 2005/09/13 15:24:57 neilc Exp $
|
2003-03-20 08:02:11 +01:00
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
|
|
|
<refentry id="SQL-ALTERSEQUENCE">
|
|
|
|
<refmeta>
|
|
|
|
<refentrytitle id="SQL-ALTERSEQUENCE-TITLE">ALTER SEQUENCE</refentrytitle>
|
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
2003-08-31 19:32:24 +02:00
|
|
|
|
2003-03-20 08:02:11 +01:00
|
|
|
<refnamediv>
|
|
|
|
<refname>
|
|
|
|
ALTER SEQUENCE
|
|
|
|
</refname>
|
|
|
|
<refpurpose>
|
2004-08-24 02:06:51 +02:00
|
|
|
change the definition of a sequence generator
|
2003-03-20 08:02:11 +01:00
|
|
|
</refpurpose>
|
|
|
|
</refnamediv>
|
2003-08-31 19:32:24 +02:00
|
|
|
|
|
|
|
<indexterm zone="sql-altersequence">
|
|
|
|
<primary>ALTER SEQUENCE</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2003-03-20 08:02:11 +01:00
|
|
|
<refsynopsisdiv>
|
|
|
|
<synopsis>
|
2003-09-22 02:16:58 +02:00
|
|
|
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> [ INCREMENT [ BY ] <replaceable class="parameter">increment</replaceable> ]
|
2003-03-20 08:02:11 +01:00
|
|
|
[ MINVALUE <replaceable class="parameter">minvalue</replaceable> | NO MINVALUE ] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> | NO MAXVALUE ]
|
|
|
|
[ RESTART [ WITH ] <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ [ NO ] CYCLE ]
|
2005-08-01 18:11:14 +02:00
|
|
|
ALTER SEQUENCE <replaceable class="parameter">name</replaceable> SET SCHEMA <replaceable class="parameter">new_schema</replaceable>
|
2003-03-20 08:02:11 +01:00
|
|
|
</synopsis>
|
2003-09-09 20:28:53 +02:00
|
|
|
</refsynopsisdiv>
|
2003-03-20 08:02:11 +01:00
|
|
|
|
2003-09-09 20:28:53 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<command>ALTER SEQUENCE</command> changes the parameters of an existing
|
2005-08-01 18:11:14 +02:00
|
|
|
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.
|
2003-09-09 20:28:53 +02:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Parameters</title>
|
|
|
|
|
|
|
|
<para>
|
2003-03-20 08:02:11 +01:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2003-09-22 02:16:58 +02:00
|
|
|
<term><replaceable class="parameter">name</replaceable></term>
|
2003-03-20 08:02:11 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-11-01 02:56:29 +01:00
|
|
|
The name (optionally schema-qualified) of a sequence to be altered.
|
2003-03-20 08:02:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">increment</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-11-01 02:56:29 +01:00
|
|
|
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.
|
2003-03-20 08:02:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">minvalue</replaceable></term>
|
2003-11-01 02:56:29 +01:00
|
|
|
<term><literal>NO MINVALUE</literal></term>
|
2003-03-20 08:02:11 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-11-01 02:56:29 +01:00
|
|
|
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.
|
2003-03-20 08:02:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">maxvalue</replaceable></term>
|
2003-11-01 02:56:29 +01:00
|
|
|
<term><literal>NO MAXVALUE</literal></term>
|
2003-03-20 08:02:11 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-11-01 02:56:29 +01:00
|
|
|
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.
|
2003-03-20 08:02:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">start</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-11-01 02:56:29 +01:00
|
|
|
The optional clause <literal>RESTART WITH <replaceable
|
|
|
|
class="parameter">start</replaceable></literal> changes the
|
|
|
|
current value of the sequence.
|
2003-03-20 08:02:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">cache</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-11-01 02:56:29 +01:00
|
|
|
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.
|
2003-03-20 08:02:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2005-09-13 17:24:57 +02:00
|
|
|
<term><literal>CYCLE</literal></term>
|
2003-03-20 08:02:11 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-11-01 02:56:29 +01:00
|
|
|
The optional <literal>CYCLE</literal> key word 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.
|
2003-03-20 08:02:11 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2003-11-01 02:56:29 +01:00
|
|
|
<varlistentry>
|
2005-09-13 17:24:57 +02:00
|
|
|
<term><literal>NO CYCLE</literal></term>
|
2003-11-01 02:56:29 +01:00
|
|
|
<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 behaviour will be
|
|
|
|
maintained.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2005-08-01 18:11:14 +02:00
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">new_schema</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The new schema for the sequence.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2003-03-20 08:02:11 +01:00
|
|
|
</variablelist>
|
|
|
|
</para>
|
2003-09-09 20:28:53 +02:00
|
|
|
</refsect1>
|
2003-03-20 08:02:11 +01:00
|
|
|
|
2003-09-09 20:28:53 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
2003-03-20 08:02:11 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Restart a sequence called <literal>serial</literal>, at 105:
|
2003-11-01 02:56:29 +01:00
|
|
|
<programlisting>
|
2003-03-20 08:02:11 +01:00
|
|
|
ALTER SEQUENCE serial RESTART WITH 105;
|
2003-11-01 02:56:29 +01:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
2003-03-20 08:02:11 +01:00
|
|
|
</refsect1>
|
|
|
|
|
2003-09-09 20:28:53 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
2003-03-20 08:02:11 +01:00
|
|
|
<para>
|
2003-09-09 20:28:53 +02:00
|
|
|
To avoid blocking of concurrent transactions that obtain numbers from the
|
|
|
|
same sequence, <command>ALTER SEQUENCE</command> is never rolled back;
|
|
|
|
the changes take effect immediately and are not reversible.
|
2003-03-20 08:02:11 +01:00
|
|
|
</para>
|
2003-09-09 20:28:53 +02:00
|
|
|
|
2003-06-12 09:49:43 +02:00
|
|
|
<para>
|
2003-09-09 20:28:53 +02:00
|
|
|
<command>ALTER SEQUENCE</command> will not immediately affect
|
2005-09-13 17:24:57 +02:00
|
|
|
<function>nextval</> results in backends,
|
2003-09-09 20:28:53 +02:00
|
|
|
other than the current one, that have preallocated (cached) sequence
|
|
|
|
values. They will use up all cached values prior to noticing the changed
|
|
|
|
sequence parameters. The current backend will be affected immediately.
|
2003-06-12 09:49:43 +02:00
|
|
|
</para>
|
2005-08-01 18:11:14 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Some variants of <command>ALTER TABLE</command> can be used with
|
|
|
|
sequences as well; for example, to rename a sequence use <command>ALTER
|
|
|
|
TABLE RENAME</command>.
|
|
|
|
</para>
|
2003-03-20 08:02:11 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
|
2003-09-09 20:28:53 +02:00
|
|
|
<refsect1>
|
2004-11-27 22:27:08 +01:00
|
|
|
<title>Compatibility</title>
|
2003-03-20 08:02:11 +01:00
|
|
|
|
2004-11-27 22:27:08 +01:00
|
|
|
<para>
|
2005-08-01 18:11:14 +02:00
|
|
|
<command>ALTER SEQUENCE</command> conforms with <acronym>SQL:2003</acronym>,
|
|
|
|
except for the <literal>SET SCHEMA</literal> variant, which is a
|
|
|
|
<productname>PostgreSQL</productname> extension.
|
2004-11-27 22:27:08 +01:00
|
|
|
</para>
|
2003-03-20 08:02:11 +01:00
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
<!-- 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:
|
|
|
|
-->
|