![]() Because of that, the sequence is also dropped if we drop the associated column or the whole table. Of our cycled sequence is descending, the next generated value after the limit is the maximum.Īn important part of the sequence created by the When a cycled sequence reaches its limits, the next generated value is the minimum. We could prevent that by using theĬYCLE option. The default value is 1.īecause the sequence is not cycled, getting a new value from the sequence after reaching its maximum results in error. The above gives us a sequence with a maximum value of 9223372036854775807, which equals 2⁶³−1.Ĭache option specifies how many numbers should be preallocated in memory for faster access. However, we can use theīigserial type instead if we want a more extensive sequence. ![]() Serial types gives us a sequence with a maximum value of 2147483647, which equals 2 31 − 1. We could specify a negative value to define a descending sequence instead. Each time we get a new value from the sequence, our sequence increments by one. The new name for the sequence.There are a few things to note above. The user name of the new owner of the sequence. Specifying OWNED BY NONE removes any existing association, making the sequence “ free-standing”. The specified table must have the same owner and be in the same schema as the sequence. If specified, this association replaces any previously specified association for the sequence. The OWNED BY 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. It cannot be applied to a temporary sequence. This form changes the sequence from unlogged to logged or vice-versa (see CREATE SEQUENCE). If neither CYCLE or NO CYCLE are specified, the old cycle behavior will be maintained. If the optional NO CYCLE key word is specified, any calls to nextval after the sequence has reached its maximum value will return an error. If the limit is reached, the next number generated will be the minvalue or maxvalue, respectively. ![]() The optional CYCLE key word can be used to enable the sequence to wrap around when the maxvalue or minvalue has been reached by an ascending or descending sequence respectively. If unspecified, the old cache value will be maintained. The minimum value is 1 (only one value can be generated at a time, i.e., no cache). The clause CACHE cache enables sequence numbers to be preallocated and stored in memory for faster access. If that's not the desired mode of operation, setval should be used. In contrast to a setval call, a RESTART operation on a sequence is transactional and blocks concurrent transactions from obtaining numbers from the same sequence. Writing RESTART with no restart value is equivalent to supplying the start value that was recorded by CREATE SEQUENCE or last set by ALTER SEQUENCE START WITH. This is similar to calling the setval function with is_called = false: the specified value will be returned by the next call of nextval. The optional clause RESTART changes the current value of the sequence. This has no effect on the current sequence value it simply sets the value that future ALTER SEQUENCE RESTART commands will use. The optional clause START WITH start changes the recorded start value of the sequence. If neither option is specified, the current maximum value will be maintained. If NO MAXVALUE is specified, the defaults of the maximum value of the data type and -1 for ascending and descending sequences, respectively, will be used. The optional clause MAXVALUE maxvalue determines the maximum value for the sequence. If neither option is specified, the current minimum value will be maintained. If NO MINVALUE is specified, the defaults of 1 and the minimum value of the data type for ascending and descending sequences, respectively, will be used. The optional clause MINVALUE minvalue determines the minimum value a sequence can generate. If unspecified, the old increment value will be maintained. A positive value will make an ascending sequence, a negative one a descending sequence. The clause INCREMENT BY increment is optional. If the minimum and maximum values do not fit into the new data type, an error will be generated. Otherwise, the minimum and maximum values are preserved, unless new values are given as part of the same command. Valid types are smallint, integer, and bigint.Ĭhanging the data type automatically changes the minimum and maximum values of the sequence if and only if the previous minimum and maximum values were the minimum or maximum value of the old data type (in other words, if the sequence had been created using NO MINVALUE or NO MAXVALUE, implicitly or explicitly). The optional clause AS data_type changes the data type of the sequence. ![]() IF EXISTSĭo not throw an error if the sequence does not exist. The name (optionally schema-qualified) of a sequence to be altered.
0 Comments
Leave a Reply. |