ALTER SEQUENCE
Change the definition of a sequence generator.
Synopsis
ALTER SEQUENCE <name>
[INCREMENT [BY] <value>]
[MINVALUE <minvalue> | NO MINVALUE]
[MAXVALUE <maxvalue> | NO MAXVALUE]
[RESTART [ WITH ] <start>]
[CACHE <cache>]
[[NO] CYCLE]
[OWNED BY { <table>.<column> | NONE }]
Description
ALTER SEQUENCE changes the parameters of an existing sequence generator. Any parameters not specifically set in the ALTER SEQUENCE command retain their prior setting.
You must own the sequence to use ALTER SEQUENCE.
Parameters
NO MINVALUE
NO MINVALUE is specified, then defaults will be used. The defaults are 1 and -263-1 for ascending and descending sequences, respectively.NO MAXVALUE
NO MAXVALUE is specified, then default values will be used. The defaults are 263-1 and -1 for ascending and descending sequences, respectively.NO CYCLE
NO CYCLE is specified, any calls to nextval() after the sequence has reached its maximum value will return an error. If not specified, NO CYCLE is the default.OWNED BY NONE
OWNED BY NONE removes any existing association.Notes
ALTER SEQUENCE will not immediately affect 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.
Some variants of ALTER TABLE can be used with sequences as well; for example, to rename a sequence use ALTER TABLE RENAME.
Examples
Restart the sequence named myseq:
ALTER SEQUENCE myseq RESTART WITH 111;
Change the increment value for the sequence named myseq:
ALTER SEQUENCE myseq INCREMENT BY 3;
Compatibility
CREATE SEQUENCE conforms to the SQL standard, with the exception that the OWNED BY clause is a HAWQ extension.