alter_sequence 中文man頁面
NAME
ALTER SEQUENCE - 更改一個序列生成器的定義
SYNOPSIS
ALTER SEQUENCE name [ INCREMENT [ BY ] increment ] [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ] [ RESTART [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
DESCRIPTION 描述
ALTER SEQUENCE 命令修改一個現有的序列發生器的參數。 任何沒有明確在 ALTER SEQUENCE 命令里聲明的參數都將保留原先的設置。
PARAMETERS 參數
- name
一個要修改的序列的名字(可以有模式修飾)。- increment
- INCREMENT BY increment 子句是可選的。一個正數會讓序列成為遞增序列,負數則成為遞減序列。 如果沒有聲明,將沿用原來的遞增值。
- minvalue
- NO MINVALUE
可選的子句 MINVALUE minvalue 決定一個序列可以生成的最小的值。如果聲明了 NO MINVALUE,將使用缺省值, 對于遞增和遞減的序列分別是 1 和 -2^63-1。如果沒有聲明任何選項,則沿用當前的最小值。- maxvalue
- NO MAXVALUE
可選的子句 MAXVALUE maxvalue 決定序列的***值。如果聲明了 NO MAXVALUE,則使用缺省值,對于遞增和遞減的序列分別是 2^63-1 和 -1。如果兩個選項都沒有聲明, 則沿用當前的***值。- start
可選的 RESTART WITH start 子句允許序列可以在任何地方開始。- cache
- CACHE cache 選項打開序列號預分配并存儲在內存緩沖的功能。最小值是 1 (也就是每次只能生成一個數值,沒有緩沖)。 如果沒有聲明,將沿用舊的緩沖值。
- CYCLE
可選的鍵字 CYCLE 可以用于允許序列在達到遞增序列的 maxvalue 或者遞減序列的 minvalue的時候重疊使用。 如果達到了極限,那么生成的下一個數字將分別是 minvalue 或 maxvalue。- NO CYCLE
如果聲明了可選鍵字 NO CYCLE,任何在序列達到其***極限后對 nextval 的調用都將返回錯誤。 如果既未聲明 CYCLE 也未聲明 NO CYCLE, 那么將沿用原有的循環行為。
EXAMPLES 例子
從 105 開始重新開始一個叫 serial 的序列:
ALTER SEQUENCE serial RESTART WITH 105;
NOTES 注意
為了避免并發的事務從同一個序列獲取數值的時候被阻塞住,ALTER SEQUENCE 操作從來不會回滾; 修改馬上生效并且不能恢復。
ALTER SEQUENCE 將不會立即影響后端的 nextval 結果,除了當前的之外, 因為它又已經緩沖了的序列號。它們只有再使用光所有已經緩沖的數值之后才能意識到改變了的序列參數。當前后端將立即被影響。
#p#
NAME
ALTER SEQUENCE - alter the definition of a sequence generator
SYNOPSIS
ALTER SEQUENCE name [ INCREMENT [ BY ] increment ] [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ] [ RESTART [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
DESCRIPTION
ALTER SEQUENCE changes the parameters of an existing sequence generator. Any parameter not specifically set in the ALTER SEQUENCE command retains its prior setting.
PARAMETERS
- name
- The name (optionally schema-qualified) of a sequence to be altered.
- increment
- The clause INCREMENT BY increment 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.
- minvalue
- NO MINVALUE
- The optional clause MINVALUE minvalue determines the minimum value a sequence can generate. If NO MINVALUE is specified, the defaults of 1 and -263-1 for ascending and descending sequences, respectively, will be used. If neither option is specified, the current minimum value will be maintained.
- maxvalue
- NO MAXVALUE
- The optional clause MAXVALUE maxvalue determines the maximum value for the sequence. If NO MAXVALUE is specified, the defaults are 263-1 and -1 for ascending and descending sequences, respectively, will be used. If neither option is specified, the current maximum value will be maintained.
- start
- The optional clause RESTART WITH start changes the current value of the sequence.
- cache
- The clause CACHE cache 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.
- CYCLE
- The optional CYCLE key word may 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 the limit is reached, the next number generated will be the minvalue or maxvalue, respectively.
- NO CYCLE
- 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 neither CYCLE or NO CYCLE are specified, the old cycle behaviour will be maintained.
EXAMPLES
Restart a sequence called serial, at 105:
ALTER SEQUENCE serial RESTART WITH 105;
NOTES
To avoid blocking of concurrent transactions that obtain numbers from the same sequence, ALTER SEQUENCE is never rolled back; the changes take effect immediately and are not reversible.
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 parameters. The current backend will be affected immediately.