1ALTER SEQUENCE(7)       PostgreSQL 9.2.24 Documentation      ALTER SEQUENCE(7)
2
3
4

NAME

6       ALTER_SEQUENCE - change the definition of a sequence generator
7

SYNOPSIS

9       ALTER SEQUENCE [ IF EXISTS ] name [ INCREMENT [ BY ] increment ]
10           [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
11           [ START [ WITH ] start ]
12           [ RESTART [ [ WITH ] restart ] ]
13           [ CACHE cache ] [ [ NO ] CYCLE ]
14           [ OWNED BY { table_name.column_name | NONE } ]
15       ALTER SEQUENCE [ IF EXISTS ] name OWNER TO new_owner
16       ALTER SEQUENCE [ IF EXISTS ] name RENAME TO new_name
17       ALTER SEQUENCE [ IF EXISTS ] name SET SCHEMA new_schema
18

DESCRIPTION

20       ALTER SEQUENCE changes the parameters of an existing sequence
21       generator. Any parameters not specifically set in the ALTER SEQUENCE
22       command retain their prior settings.
23
24       You must own the sequence to use ALTER SEQUENCE. To change a sequence's
25       schema, you must also have CREATE privilege on the new schema. To alter
26       the owner, you must also be a direct or indirect member of the new
27       owning role, and that role must have CREATE privilege on the sequence's
28       schema. (These restrictions enforce that altering the owner doesn't do
29       anything you couldn't do by dropping and recreating the sequence.
30       However, a superuser can alter ownership of any sequence anyway.)
31

PARAMETERS

33       name
34           The name (optionally schema-qualified) of a sequence to be altered.
35
36       IF EXISTS
37           Do not throw an error if the sequence does not exist. A notice is
38           issued in this case.
39
40       increment
41           The clause INCREMENT BY increment is optional. A positive value
42           will make an ascending sequence, a negative one a descending
43           sequence. If unspecified, the old increment value will be
44           maintained.
45
46       minvalue, NO MINVALUE
47           The optional clause MINVALUE minvalue determines the minimum value
48           a sequence can generate. If NO MINVALUE is specified, the defaults
49           of 1 and -263-1 for ascending and descending sequences,
50           respectively, will be used. If neither option is specified, the
51           current minimum value will be maintained.
52
53       maxvalue, NO MAXVALUE
54           The optional clause MAXVALUE maxvalue determines the maximum value
55           for the sequence. If NO MAXVALUE is specified, the defaults are
56           263-1 and -1 for ascending and descending sequences, respectively,
57           will be used. If neither option is specified, the current maximum
58           value will be maintained.
59
60       start
61           The optional clause START WITH start changes the recorded start
62           value of the sequence. This has no effect on the current sequence
63           value; it simply sets the value that future ALTER SEQUENCE RESTART
64           commands will use.
65
66       restart
67           The optional clause RESTART [ WITH restart ] changes the current
68           value of the sequence. This is equivalent to calling the setval
69           function with is_called = false: the specified value will be
70           returned by the next call of nextval. Writing RESTART with no
71           restart value is equivalent to supplying the start value that was
72           recorded by CREATE SEQUENCE or last set by ALTER SEQUENCE START
73           WITH.
74
75       cache
76           The clause CACHE cache enables sequence numbers to be preallocated
77           and stored in memory for faster access. The minimum value is 1
78           (only one value can be generated at a time, i.e., no cache). If
79           unspecified, the old cache value will be maintained.
80
81       CYCLE
82           The optional CYCLE key word can be used to enable the sequence to
83           wrap around when the maxvalue or minvalue has been reached by an
84           ascending or descending sequence respectively. If the limit is
85           reached, the next number generated will be the minvalue or
86           maxvalue, respectively.
87
88       NO CYCLE
89           If the optional NO CYCLE key word is specified, any calls to
90           nextval after the sequence has reached its maximum value will
91           return an error. If neither CYCLE or NO CYCLE are specified, the
92           old cycle behavior will be maintained.
93
94       OWNED BY table_name.column_name, OWNED BY NONE
95           The OWNED BY option causes the sequence to be associated with a
96           specific table column, such that if that column (or its whole
97           table) is dropped, the sequence will be automatically dropped as
98           well. If specified, this association replaces any previously
99           specified association for the sequence. The specified table must
100           have the same owner and be in the same schema as the sequence.
101           Specifying OWNED BY NONE removes any existing association, making
102           the sequence “free-standing”.
103
104       new_owner
105           The user name of the new owner of the sequence.
106
107       new_name
108           The new name for the sequence.
109
110       new_schema
111           The new schema for the sequence.
112

NOTES

114       To avoid blocking of concurrent transactions that obtain numbers from
115       the same sequence, ALTER SEQUENCE's effects on the sequence generation
116       parameters are never rolled back; those changes take effect immediately
117       and are not reversible. However, the OWNED BY, OWNER TO, RENAME TO, and
118       SET SCHEMA clauses cause ordinary catalog updates that can be rolled
119       back.
120
121       ALTER SEQUENCE will not immediately affect nextval results in backends,
122       other than the current one, that have preallocated (cached) sequence
123       values. They will use up all cached values prior to noticing the
124       changed sequence generation parameters. The current backend will be
125       affected immediately.
126
127       ALTER SEQUENCE does not affect the currval status for the sequence.
128       (Before PostgreSQL 8.3, it sometimes did.)
129
130       For historical reasons, ALTER TABLE can be used with sequences too; but
131       the only variants of ALTER TABLE that are allowed with sequences are
132       equivalent to the forms shown above.
133

EXAMPLES

135       Restart a sequence called serial, at 105:
136
137           ALTER SEQUENCE serial RESTART WITH 105;
138

COMPATIBILITY

140       ALTER SEQUENCE conforms to the SQL standard, except for the START WITH,
141       OWNED BY, OWNER TO, RENAME TO, and SET SCHEMA clauses, which are
142       PostgreSQL extensions.
143

SEE ALSO

145       CREATE SEQUENCE (CREATE_SEQUENCE(7)), DROP SEQUENCE (DROP_SEQUENCE(7))
146
147
148
149PostgreSQL 9.2.24                 2017-11-06                 ALTER SEQUENCE(7)
Impressum