1ALTER SEQUENCE() SQL Commands ALTER SEQUENCE()
2
3
4
6 ALTER SEQUENCE - change the definition of a sequence generator
7
8
10 ALTER SEQUENCE name [ INCREMENT [ BY ] increment ]
11 [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
12 [ RESTART [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
13 [ OWNED BY { table.column | NONE } ]
14 ALTER SEQUENCE name SET SCHEMA new_schema
15
16
17
19 ALTER SEQUENCE changes the parameters of an existing sequence genera‐
20 tor. Any parameters not specifically set in the ALTER SEQUENCE command
21 retain their prior settings.
22
23 You must own the sequence to use ALTER SEQUENCE. To change a
24 sequence's schema, you must also have CREATE privilege on the new
25 schema.
26
28 name The name (optionally schema-qualified) of a sequence to be
29 altered.
30
31 increment
32 The clause INCREMENT BY increment is optional. A positive value
33 will make an ascending sequence, a negative one a descending
34 sequence. If unspecified, the old increment value will be main‐
35 tained.
36
37 minvalue
38
39 NO MINVALUE
40 The optional clause MINVALUE minvalue determines the minimum
41 value a sequence can generate. If NO MINVALUE is specified, the
42 defaults of 1 and -263-1 for ascending and descending sequences,
43 respectively, will be used. If neither option is specified, the
44 current minimum value will be maintained.
45
46 maxvalue
47
48 NO MAXVALUE
49 The optional clause MAXVALUE maxvalue determines the maximum
50 value for the sequence. If NO MAXVALUE is specified, the
51 defaults are 263-1 and -1 for ascending and descending
52 sequences, respectively, will be used. If neither option is
53 specified, the current maximum value will be maintained.
54
55 start The optional clause RESTART WITH start changes the current value
56 of the sequence.
57
58 cache The clause CACHE cache enables sequence numbers to be preallo‐
59 cated and stored in memory for faster access. The minimum value
60 is 1 (only one value can be generated at a time, i.e., no
61 cache). If unspecified, the old cache value will be maintained.
62
63 CYCLE The optional CYCLE key word may be used to enable the sequence
64 to wrap around when the maxvalue or minvalue has been reached by
65 an ascending or descending sequence respectively. If the limit
66 is reached, the next number generated will be the minvalue or
67 maxvalue, respectively.
68
69 NO CYCLE
70 If the optional NO CYCLE key word is specified, any calls to
71 nextval after the sequence has reached its maximum value will
72 return an error. If neither CYCLE or NO CYCLE are specified,
73 the old cycle behavior will be maintained.
74
75 OWNED BY table.column
76
77 OWNED BY NONE
78 The OWNED BY option causes the sequence to be associated with a
79 specific table column, such that if that column (or its whole
80 table) is dropped, the sequence will be automatically dropped as
81 well. If specified, this association replaces any previously
82 specified association for the sequence. The specified table must
83 have the same owner and be in the same schema as the sequence.
84 Specifying OWNED BY NONE removes any existing association, mak‐
85 ing the sequence ``free-standing''.
86
87 new_schema
88 The new schema for the sequence.
89
91 Restart a sequence called serial, at 105:
92
93 ALTER SEQUENCE serial RESTART WITH 105;
94
95
97 To avoid blocking of concurrent transactions that obtain numbers from
98 the same sequence, ALTER SEQUENCE's effects on the sequence generation
99 parameters are never rolled back; those changes take effect immediately
100 and are not reversible. However, the OWNED BY and SET SCHEMA clauses
101 are ordinary catalog updates and can be rolled back.
102
103 ALTER SEQUENCE will not immediately affect nextval results in backends,
104 other than the current one, that have preallocated (cached) sequence
105 values. They will use up all cached values prior to noticing the
106 changed sequence generation parameters. The current backend will be
107 affected immediately.
108
109 Some variants of ALTER TABLE can be used with sequences as well; for
110 example, to rename a sequence use ALTER TABLE RENAME.
111
113 ALTER SEQUENCE conforms to the SQL standard, except for the OWNED BY
114 and SET SCHEMA clauses, which are PostgreSQL extensions.
115
117 CREATE SEQUENCE [create_sequence(7)], DROP SEQUENCE [drop_sequence(l)]
118
119
120
121SQL - Language Statements 2008-06-08 ALTER SEQUENCE()